zoukankan      html  css  js  c++  java
  • 18 UI美化自定义主题样式代码

    • 自定义主题 假设我们我们对现有的样式不大满意 那么可在工程目录res/values下的styles.xml自定义

    方法:
    1. res/values下的styles.xml文件中自定义一个标签

    <style name ="你想要取的样式名" parent="你想继承的样式">
     <item name="重写的属性名">新属性</item>
      <item name="...">...</item>
     .
     .
    
    </style>

    例子: styles.xml文件增加的字段

     <color name="customcolor">#b0b0ff</color>
        <!-- 自定义的主题    name ="主题的名称 " parent="继承于  系统主题"   改变背景颜色 -->
        <!-- parent="@style/android:Theme.Light" 也可以写成 parent="android:Theme.Light" -->
        <style name="CustomTheme" parent="@style/android:Theme.Light">
            <!--  这里必须自定义一个color放入 不然报错 -->
            <item name="android:windowBackground">@color/customcolor</item>
        </style>

    使用:在清单文件中AndroidManifest.xml中apliction或者activity中使用(如果activity没有定义主题那么默认使用apliction的)

    例子:

     <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.qf.day18_resource_demo.MainActivity"
                android:label="@string/app_name" 
                android:theme="@style/CustomTheme"
                >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    • 关于继承样式两种方式

      • 方式一
      <style name="father">
               <item name="android:textColor">#f00</item>
                <item name="android:layout_width">wrap_content</item>
          </style>
      
          <!-- 继承父类所有属性 并且可重写父类属性 -->
           <style name="father.son">
                <item name="android:layout_width">wrap_content</item>
          </style>

      调用方式

       <activity
                  android:name="com.qf.day18_resource_demo.MainActivity"
                  android:label="@string/app_name" 
                  android:theme="@style/father.son"
                  >
      • 方式二
        <style name="father">
               <item name="android:textColor">#f00</item>
                <item name="android:layout_width">wrap_content</item>
          </style>
      
          <!-- 继承父类所有属性 并且可重写父类属性 -->
           <style name="son" parent="@style/father">
                <item name="android:layout_width">wrap_content</item>
          </style>
      • 调用
     <activity
                android:name="com.qf.day18_resource_demo.MainActivity"
                android:label="@string/app_name" 
                android:theme="@style/son"
                >

    • 假设我们有一天很多控件的样式都是一样的 我们可以抽取样式放入style中
     <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/holo_red_light"
            android:text="抽奖"
            />
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/holo_red_light"
            android:text="再来一次"
            />
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/holo_red_light"
            android:text="不玩了"
            />
    • 上面的例子可以看到三个Button有多个重复样式 ,那么我们现在抽取公共样式 于
      目录res/values下的styles.xml自定义
    <style name="MyButtonStyle">
            <item name="android:layout_width">wrap_content</item>
            <item name="android:layout_height">wrap_content</item>
            <item name=" android:textColor">@android:color/holo_red_light</item>
    
        </style>

    使用方法:

     <Button 
            style="@style/MyButtonStyle"
            android:text="抽奖"
            />
        <Button 
           style="@style/MyButtonStyle"
            android:text="再来一次"
            />
        <Button 
           style="@style/MyButtonStyle"
            android:text="不玩了"
  • 相关阅读:
    curl java 模拟http请求
    Redis 个人理解总结
    算法时间复杂度的表示法O(n²)、O(n)、O(1)、O(nlogn)等是什么意思?
    RESTful 个人理解总结
    springcloud(五):熔断监控Hystrix Dashboard和Turbine
    springcloud(四):熔断器Hystrix
    springcloud(三):服务提供与调用
    springcloud(二):注册中心Eureka
    springcloud(一):大话Spring Cloud
    Spring Cloud在国内中小型公司用的起来吗?
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152235.html
Copyright © 2011-2022 走看看