• android样式之按钮&&图片


    在drawable-hdpi中添加xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true" > 
            <shape>
                <gradient android:startColor="#ff8c00" android:endColor="#FFFFFF" android:angle="270" /> 
                <stroke android:width="2dp" android:color="#dcdcdc" /> 
                <corners android:radius="10dp" />
                <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" />
            </shape>
    
        </item>
    
        <item android:state_focused="true" >
            <shape>
                <gradient android:startColor="#ffc2b7" android:endColor="#ffc2b7" android:angle="270" />
                <stroke android:width="2dp" android:color="#dcdcdc" />
                <corners android:radius="10dp" />
                <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" />
            </shape>
        </item>
    
        <item>
            <shape>
                 <gradient android:startColor="#ff9d77" android:endColor="#ff9d77" android:angle="270" />
                <stroke android:width="2dp" android:color="#fad3cf" />
                <corners android:radius="10dp" />
                <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" />
            </shape>
        </item>            
    </selector>
    Button样式文件
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@drawable/red" android:state_pressed="true"/>
        <!-- 被按压的时候 显示什么图形  注:图片大会异常 -->
        <item android:drawable="@drawable/red" android:state_focused="true"/>
        <!-- 获取焦点 -->
        <item android:drawable="@drawable/backward"/>
        <!-- 默认的时候 显示的图形 -->
    </selector>
    ImageView样式文件

    图片太大程序会异常退出

    设置android:background属性即可

    <ImageView
    android:id="@+id/image_back"
    android:clickable="true"
    android:layout_width="30dip"
    android:layout_height="30.0dip"
    android:scaleType="fitXY"
    android:background="@drawable/style_back_selector" />

  • 相关阅读:
    2021牛客暑期多校训练营5
    二分图知识点温习
    Codeforces Round #735 (Div. 2)
    牛客比赛订正(3,4)
    Harbour.Space Scholarship Contest 2021-2022 (Div. 1 + Div. 2) Editorial题解
    关于球的相关知识
    AtCoder Beginner Contest 210题解
    P7077 [CSP-S2020] 函数调用
    偏序问题学习笔记
    P1606 [USACO07FEB]Lilypad Pond G
  • 原文地址:https://www.cnblogs.com/huangzhen22/p/4803509.html
Copyright © 2020-2023  润新知