Android主题和样式资源

样式作用在控件上,是一个包含一个或多个控件属性的集合。

定义位置:res/values目录下的styles.xml文件中。

<resources>
    <style name="tv_style">
            <item name="android:layout_width">wrap_content</item>
            <item name="android:layout_height>wrap_content</item>
            <item name="android:textColor">#ffOOOO</item>
    </style>
    <style name="btn_style" parent="tv_style">
        <item name="android:textColor">#OOffOO</item>
    </style>
</resources>

在布局文件中给控件设置style属性即可

<Text View
    android:id="@+id/tv"
    style="@style/tv_style"/>
<Button 
    android:id="@+id/btn"
    style="@style/btn_style"/>

@就是R文件

主题作用在Application或Activity上。

新建一个应用时,系统会在style.xml中创建一个名字为Appthem的默认主题,并自动调用该默认的主题。

AndroidMainfest.xml    

<application>
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
</application>

自定义主题,放在styles.xml中,自定义的全屏的没有遮盖物的主题,

<resources>

    <style name="ThemNoTitle" parent="AppTheme">
      
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@cnull</item>
    </style>

</resources>

应用的两个方式,

在清单文件中应用:Android:theme="@style/ThemeNoTitle"

在Java代码中应用:setTheme(R.style.ThemeNoTItle);该方法需要在setContentView()之前调用。

 

      

 

 

 


版权声明:本文为zhaojie911272507原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。