android 让Ui更近一步


    1、颜色资源

            在valuses/colors.xml

            引用 直接在layout或者style等其他文件中@color/name

            形式 :

<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>

    2、字符串资源

            values/strings.xml

            引用直接在layout或者style等文件中@string/name

            形式:

<resources>
    <string name="app_name">test18_4_26_1</string>
</resources>

    3、样式资源

    values/styles.xml

            直接在layout或者theme中引用 @style/name

            形式:

<style name="mystyle" parent="AlertDialog.AppCompat.Light">
        <item name="android:background">@color/red</item>
    </style>
    style的继承:父style.子style    这种继承方式需要在同一个包内
                    
          或者       指定parent=“”
   

    4、主题

       values/styles.xml        主题是一个style在manifest中引用,将成为该应得默认style

            直接在manifest引用

        形式

<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>
</style>
    

            一般创建应用时系统就会默认给manifest引用一个theme(主题)

                如下:

        manifest中

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.chenk.test18_4_25_3">

    <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">
        style中
<resources>

    <!-- Base application theme. -->
    <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>    
    </style>

       4.1、 Appcompat自带的三大主题

            Theme.AppCompat   深色主题

            Theme.AppCompat.Light   浅色主题

            Theme.AppCompat.Light.DarkActionBar  带深色工具栏的浅色主题


            既然如此我们可以自定义主题来方便我们的ui设计,但是我们只能修改一部分属性,也不能完全抛弃

            所以一般继承以上三大主题之一,然后修改部分可修改的属性

                步骤:1.在style打开主题

                          2.引用三大主题之一

                          3.定制主题属性

4.2 覆盖主题属性  (可以给同类的组件添加同样的属性)

    提示:我们并不知道那些属性可以修该   

        从theme.AppCompat开始 按住ctrl和鼠标左键向上追溯(继承树比较深)

找到相应的组件 看属性。然后定义一个style,在style中继承相应的组件,修改属性,最后在主题中引用



5、xm drawable资源

在andoid中凡是要在屏幕中绘制的东西都叫做drawable,如抽象图形,Drawable类的子类代码,位图图像等


5.1、shape drawable(表示图形的形状。有四个选项:rectangle(矩形),oval(圆形),line(横线),ring(圆环)。默认形状是矩形。line和ring时必须要通过 < stroke >标签来指定线的宽度和颜色信息。

<shape    
    xmlns:android="http://schemas.android.com/apk/res/android"    
    android:shape=["rectangle" | "oval" | "line" | "ring"] >    
</shape>

< corners> 圆角效果

表示shape的四个角的角度,它只适用于矩形shape, 这里的角度指圆角的程度,单位是px,有5个属性: android:radius=”integer” 四个角设定相同的角度,优先级比较低,会被其他的四个属性覆盖

android:topLeftRadius=”integer”

android:topRightRadius=”integer”

android:bottomLeftRadius=”integer”

android:bottomRightRadius=”integer”


< gradient> 渐变效果

它与< solid>标签是互相排斥的,gradient表示渐变效果。

< solid> 填充色(单一色)

< stroke> 描边

< padding> 空白

< size> shape的大小


5.2、state list drawable(具体作用是在该对象下设立俩个状态,button按下去是一个状态,没按是一个状态)

1、在res/drawable文件下创建selector.xml,示例代码如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="false"
        android:drawable="@drawable/title_button_back">
    </item>
    <item
        android:state_pressed="true"
        android:drawable="@drawable/title_button_back_h">
    </item>
    <item
        android:state_window_focused="false"
        android:drawable="@drawable/title_button_back">
    </item>
</selector>
2、编写布局文件,为布局文件中的ImageButton设置selector,示例代码如下:

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent">  
    <Button 
        android:id="@+id/title_IB"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:background="@drawable/selector" 
        android:layout_marginRight="4dp" 
        android:layout_centerVertical="true">
    </Button>  
</RelativeLayout>

5.3、layer list drawable (将俩个drawable对象的xml合二为一,时期显示具有复杂的效果)

    

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="oval">
                <solid
                    android:color="@color/red"/>
            </shape>
        </item>
        <item>
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="oval">
                <stroke
                    android:width="4dp"
                    android:color="@color/red">
                </stroke>
            </shape>
        </item>
</layer-list>





    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值