customUIStyle自定义用户界面

Demo 下载地址   http://download.csdn.net/detail/mwq30123/6781643

相关Theme,Style,Attr

  Theme

    Collections of properties for the whole Activityor Application

    Definition

           OS :  frameworks/base/core/res/res/values/themes.xml

           APP : res/values/styles.xml

    Apply Theme

       By XML

             Add “android:theme” to <activity> or <Application>element in android manifest

       By code

             By setTheme() method which mustbe called before setContentView()


   Styles

     Collections of properties forindividual View or window

     Definition

           OS :frameworks/base/core/res/res/values/styles.xml

           APP : res/values/styles.xml

     Apply

            By XML

                   Add style attribute to a Viewelement

                  Example:

                  <EditTextid="@+id/editText1

                       style="@style/TextStyle“

                        …… />

  Attr

      Define the attribute’s name and format for theme , style or layoutUsing

      Definition

            OS :  frameworks/base/core/res/res/values/attrs.xml

            APP : res/values/attrs.xml

      Apply

             By XML

                          <Button

                          style="?android:attr/buttonStyleSmall

                   …… />

              Ps: buttonStyleSmall   defined in os ’s attrs.xml  and used inos’s theme.xml

 

Example – define button background.

 

     1.  Direct Set bg.

     android:background="#00ff00“

    2.  Custom style

     <style name="MyBlueButton">

         <itemname="android:background">#0000ff</item>

     </style>

       style="@style/MyBlueButton

     3.  Custom Theme

     • <style name="MyYellowButton"parent="android:Widget.Button">

       <item name="android:background">#ffff00</item>

      </style>

       <style name="MyYellowTheme"parent="android:Theme.Light">

           <item name="android:buttonStyle">@style/MyYellowButton</item>

       </style>

     • <activity

           android:name="com.sb.MainActivity"

          android:theme="@style/MyYellowTheme" >

      4. OS Theme’ s Attr

          style="?android:attr/buttonStyleSmall“

      5. Custom Attr And CustomView

       •   in attr.xml

               <declare-styleable name="CustomAttr">

                   <attrname="bgColor" format="reference|color"/>

                </declare-styleable>

        •   in layout.xml

                 <AbsoluteLayoutxmlns:android="http://schemas.android.com/apk/res/android"

                      xmlns:custom="http://schemas.android.com/apk/res/com.sb"

                      ……>

                        <com.sb.CustomButton

                              ……

                           custom:bgColor="#ff0000"/>

         •      class CustomButton extends Button

                 Get the bgColor In CustomButton’s construction  and  setBackgroundColor(bgColor);

               

      public class CustomButton extends Button{

            private Context mContext;
            
            public CustomButton(Context context) {

                super(context);

                mContext = context;

             }

            public CustomButton(Context context, AttributeSet attrs){

                 super(context, attrs);

                 mContext = context;

                TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CustomAttr);

                int bgColor = array.getColor(R.styleable.CustomAttr_bgColor,0x000000);

                setBackgroundColor(bgColor);

                array.recycle();

            }
      }


 

 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值