zoukankan      html  css  js  c++  java
  • Android开发学习笔记-自定义TextView属性模版

        如果项目中有很多个控件使用的是同一种样式,则为了方便,可以将样式设置到系统中去,这样使用的时候会方便很多。

        下面是自定义样式模版的方法。

    1、在style.xml文件中添加自己要设置的样式内容

    <resources>
    
        <!--
            Base application theme, dependent on API level. This theme is replaced
            by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    
        -->
        <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
            <!--
                Theme customizations available in newer API levels can go in
                res/values-vXX/styles.xml, while customizations related to
                backward-compatibility can go here.
    
            -->
        </style>
    
        <!-- Application theme. -->
        <style name="AppTheme" parent="AppBaseTheme">
            <item name="android:windowNoTitle">true</item>
            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        </style>
    
        <style name="text_content">
            <item name="android:layout_width">match_parent</item>
            <item name="android:layout_height">55dp</item>
            <item name="android:layout_marginLeft">5dp</item>
            <item name="android:layout_marginTop">5dp</item>
            <!-- 自定义TextView样式 -->
        </style>
    
    </resources>

    2、在前端进行引用

     <TextView
          android:id="@+id/baom1"
          style="@style/text_content"
          android:gravity="center_vertical"
          android:drawableLeft="@android:drawable/star_big_on"
          android:text="baojing" />

    3、说明:

         在xml中,name为引用的名称,item为属性名称以及对应的值。

  • 相关阅读:
    最近。。。。。。。。。。。
    SQLServer中 多行合成一行 的方法.
    操作Excel
    minheight和height
    提高网页效率的14条准则
    IE和FireFox的Javascript的事件和事件处理总结
    id和class到底要用哪一个?
    XML.parentNode 与 parentElement 的说明
    window.event 对象详解
    padding和margin到底要用哪一个?
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/4021303.html
Copyright © 2011-2022 走看看