Android Development threme and style of UI Interface

  • 2021-07-22 11:16:05
  • OfStack

themes. xml and style. xml of Android system (located at\ base\ core\ res\ res\ values\) contain many style defined by the system. It is recommended to choose the appropriate one among them and then inherit the modification.

1. Theme 1 in threme android is generally used at the form level to change the form style

1. Theme:

It means default status, that is, if theme does not fill in any attributes here, it defaults to Theme

1.1, Theme_NoDisplay

It means nothing to show. It is better to just run activity, but nothing is displayed.

1.2, Theme_NoTitleBar

The style of background theme without title bar. If it is not set by default, it will display a black background

1.3, Theme_NoTitleBar_Fullscreen

Full screen style of background theme without title bar, with black background by default

2. Theme_Black:

It means black background by default.

2.1. Theme_Black_NoTitleBar:

Style without title bar with black background theme

2.2. Theme_Black_NoTitleBar_Fullscreen

Full-screen style with black background theme without title bar

3. Theme_Light

By default, the background is bright, as opposed to the black background Theme_Black.

3.1, Theme_Light_NoTitleBar

The style of a bright background theme without a title bar, as opposed to Theme_Black_NoTitleBar

3.2. Theme_Light_NoTitleBar_Fullscreen

A full-screen style with no title bar for a bright background theme, as opposed to Theme_Black_NoTitleBa_Fullscreenr

4. Theme_Dialog

Dialog Style changes the whole activity into a dialog style.

5. Theme_InputMethod

6. Theme_Panel

It means: delete all redundant window decorations and fill in an empty rectangular box. The scope of action is equivalent to removing all elements in dialog, only an empty rectangular box, and this is the default style.

6.1, Theme_Light_Panel

It means: delete all redundant window decorations and fill in an empty rectangular box. The scope of action is equivalent to removing all elements in dialog, only an empty rectangular box, and the default is the style of light.

7. Theme_Wallpaper

Meaning: Use wallpaper as theme, default state.

7.1, Theme_WallpaperSettings

It means: use wallpaper as the theme, and the default is to use dimming the previous interface as the theme

7.2, Theme_Light_WallpaperSettings

Meaning: Use wallpaper as theme, default Light status.

7.3, Theme_Wallpaper_NoTitleBar

It means: use wallpaper as the theme, and there is no title bar

7.4. Theme_Wallpaper_NoTitleBar_Fullscreen

It means: use wallpaper as the theme, and there is no title bar, and it is displayed in full screen

8. Theme_Translucent

Background in translucent state, the screen before running this activity as translucent state as the style of this activity runtime.

8.1, Theme_Translucent_NoTitleBar

In translucent state, there is no background of title bar, and the screen before running this activity is regarded as translucent state as the style of this activity runtime.

8.2, Theme_Translucent_NoTitleBar_Fullscreen

It means: a full-screen background without title bar in translucent state, and the screen before running this activity is regarded as translucent state as the style of this activity runtime.

2. Style 1 in style android is generally used for form element sectors to change the style of controls

It is understood that the attributes written in the control attributes are wrapped in a file! !

Style file specification:

<?xml version="1.0" encoding="utf-8"?>  
<resources> 
  <style name="TextStyle"> 
     <item name="android:textSize">14sp</item> 
     <item name="android:textColor">#fff</item> 
  </style> 
</resources>

Is an xml, to < resources > At the beginning, define style node, and define every 1 item of item under style.

The reference is also very simple, as follows:

<EditText id="@+id/editText1"  
    style="@style/TextStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello, World!" />

The above is just a simple application of style, and a very practical knowledge will be mentioned next, that is, the inheritance relationship of style. Only in this way can we simplify the workload of our code and make more use of the whole program logic. Its inheritance relationship can be implemented in two ways:

1. Is specified by the parent attribute
2. Specify by dot

Next, let's give examples respectively: TextView may be used most in our program, and it may have many situations, such as title, text, prompt, etc. These TextView have their similarities and differences. First, we define a passed style:

<style name="TextStyle">
    <item name="android:shadowDx">-0.5</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">0.5</item>
    <item name="android:singleLine">true</item>
    <item name="android:ellipsize">marquee</item>
</style>

The above mainly defines his shadow, single line, and what to do if it exceeds the length. Next we define a style at the title level, and title we also want these attributes, so we have to inherit it. First, we use the parent attribute to inherit

<style name="TextTitle" parent="TextStyle">
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">#fff</item>
    <item name="android:textStyle">bold</item>
</style>

The parent attribute is followed by the name of the parent class, just like the shadow of title, the font size, color discrimination and thickness come out, and we don't have to define the shadow of title. Save a lot of time. The second type of inheritance is to use parentStyle. childStyle and inherit with dots. We can also write TextTitle above:

<style name="TextStyle.TextTitle">
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">#fff</item>
    <item name="android:textStyle">bold</item>
</style>

This can also get the expected effect. The upset about this is that the name is long. When we refer to this style, we have style= "@ style/TextStyle. TextTitle". The more hierarchies we inherit, the longer the name will be.


Related articles: