Android theme style summary

Theme and style

Both themes and styles use <style>tags, but they serve completely different purposes.

style

A style is a collection of View attribute values, and only one style can be used for a view.

<Button …
  style="@style/Widget.Plaid.Button.InlineAction"/>

theme

  • A theme is a collection of named resources that can be referenced by style or layout files.
  • You can set the theme to Application/Activity/View/ViewGroup.
  • For example, Activity contains ViewGroup, and ViewGroup contains View. Set the theme to any layer of a tree structure, and this layer and the next layer will be affected. For example, if the theme is set to a ViewGroup, all child views contained in this ViewGroup will be affected by the theme. (The style is just the opposite, it only works on the set View)
<!-- AndroidManifest.xml -->
<application …
  android:theme="@style/Theme.Plaid">
  
<activity …
  android:theme="@style/Theme.Plaid.About"/>

<!-- layout/foo.xml -->
<ConstraintLayout …
  android:theme="@style/Theme.Plaid.Foo">

@ And? and @android and @attr/ and ?android:attr/

@: Reference custom resources

<string name="app_name">hello</string>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/app_name" />

?: Reference to the resources of the current topic

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/app_name"
    android:textColor="?colorPrimary"
    android:textSize="24sp" />

@android: Reference to Android's built-in system resources

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@android:mipmap/sym_def_app_icon" />

?attr/

Equivalent to?

<resources>
    <attr name="nameColor" format="color" />
</resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="nameColor">#a2a3e2</item>
</style>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/app_name"
    android:textColor="?nameColor"
    android:textSize="24sp" />

?android:attr/

Equivalent to?android

Common wording of Theme

Common writing

@android:style/Theme.Holo.Light

Writing after 4.0

@android:style/Theme.Material.xxx

Writing after 5.0

Theme.AppCompat.Light.DarkActionBar

Common theme style settings

<!--应用的主要颜色-->
<item name="colorPrimary">#ff0000</item>

<!--应用的次要颜色-->
<item name="colorPrimaryDark">#00ff00</item>

<!--默认选中颜色-->
<item name="colorAccent">@color/colorAccent</item>

<!--状态栏颜色-->
<item name="android:statusBarColor">#00000000</item>

<!-- 状态栏透明化 -->
<item name="android:windowTranslucentStatus">true</item>

<!-- 状态栏文字颜色,API23可用-->
<item name="android:windowLightStatusBar">true</item>

<!-- 全屏显示,隐藏状态栏、导航栏、底部导航栏 -->
<item name="android:windowFullscreen">true</item>

<!-- 隐藏Title -->
<item name="windowNoTitle">true</item>

<!-- 底部虚拟导航栏颜色 -->
<item name="android:navigationBarColor">#E91E63</item>

<!-- 让底部导航栏变半透明灰色,覆盖在Activity之上(默认false,activity会居于底部导航栏顶部),如果设为true,navigationBarColor 失效 -->
<item name="android:windowTranslucentNavigation">true</item>

<!--背景颜色-->
<item name="android:background">#a2a3e2</item>

<!--背景图片-->
<item name="android:windowBackground">@drawable/ic_launcher_background</item>

Control related

<!-- button 文字是否全部大写,系统默认打开 -->
<item name="android:textAllCaps">false</item>

<!-- 默认 Button,TextView的文字颜色 -->
<item name="android:textColor">#B0C4DE</item>

<!-- 默认 EditView 输入框字体的颜色 -->
<item name="android:editTextColor">#E6E6FA</item> 

<!-- RadioButton checkbox等控件的文字 -->
<item name="android:textColorPrimaryDisableOnly">#1C71A9</item>

<!-- 应用的主要文字颜色,actionBar的标题文字默认使用该颜色 -->
<item name="android:textColorPrimary">#FFFFFF</item>

<!-- 辅助的文字颜色,一般比textColorPrimary的颜色弱一点,用于一些弱化的表示 -->
<item name="android:textColorSecondary">#C1C1C1</item>

<!-- 控件选中时的颜色,默认使用colorAccent -->
<item name="android:colorControlActivated">#FF7F50</item>

<!-- 控件按压时的色调-->
<item name="android:colorControlHighlight">#FF00FF</item>

<!-- CheckBox,RadioButton,SwitchCompat等默认状态的颜色 -->
<item name="android:colorControlNormal">#FFD700</item>

<!-- 默认按钮的背景颜色 -->
<item name="android:colorButtonNormal">#1C71A9</item>

<!--屏幕方向-->
<item name="android:screenOrientation">landscape</item>

Guess you like

Origin blog.csdn.net/qq_14876133/article/details/107407047
Recommended