zoukankan      html  css  js  c++  java
  • Android自定义shape的使用

    MainActivity如下:

    package cn.testshape;
    import android.os.Bundle;
    import android.app.Activity;
    /**
     * Demo描述:
     * 自定义shape的使用
     */
    public class MainActivity extends Activity {
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);
    	}
    
    }
    


    main.xml如下:

    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
    
        <Button
            android:layout_width="250dip"
            android:layout_height="50dip"
            android:text="测试自定义shape的使用" 
            android:background="@drawable/background_selector"
            android:textColor="@drawable/textcolor_selector"
            android:layout_centerInParent="true"
            android:gravity="center"
          />
    
    </RelativeLayout>


    background_selector.xml如下:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
         <item android:drawable="@drawable/pressed_shape" android:state_pressed="true"/>
         <item android:drawable="@drawable/default_shape"/>
    </selector>


    default_shape.xml如下:

    <?xml version="1.0" encoding="utf-8"?>
        <!-- 定义矩形rectangle -->
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:shape="rectangle" >
        <!-- 定义边框颜色 -->
        <solid android:color="#d1d1d1" />
        <!-- 定义圆角弧度 -->
        <corners
            android:bottomLeftRadius="4dp"
            android:bottomRightRadius="4dp"
            android:topLeftRadius="4dp"
            android:topRightRadius="4dp" 
        />
    
    </shape>


    pressed_shape.xml如下:

    <?xml version="1.0" encoding="utf-8"?>
        <!-- 定义矩形rectangle -->
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:shape="rectangle" >
        <!-- 定义边框颜色 -->
        <solid android:color="#7bb3f8" />
        <!-- 定义圆角弧度 -->
        <corners
            android:bottomLeftRadius="4dp"
            android:bottomRightRadius="4dp"
            android:topLeftRadius="4dp"
            android:topRightRadius="4dp" 
        />
    
    </shape>


    textcolor_selector.xml如下:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
          <item android:color="#ffffff" android:state_pressed="true"/>
          <item android:color="#000000"/>
    </selector>
  • 相关阅读:
    回顾python,就当做笔记了
    测试知识回顾
    转发 Python接口自动化
    性能测试脚本调优
    java
    新的一年,希望自己有所提升,在这简单的记录,自己的学习。
    navicat 连接 mysql 出现Client does not support authentication protocol requested by server解决方案
    tomcat context配置
    tomcat host 配置
    flyway使用
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3149642.html
Copyright © 2011-2022 走看看