Android自定義shape的使用示例
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="測(cè)試自定義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>
相關(guān)文章
Material Design系列之Behavior實(shí)現(xiàn)Android知乎首頁(yè)
這篇文章主要為大家詳細(xì)介紹了Material Design系列之Behavior實(shí)現(xiàn)Android知乎首頁(yè)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
Android代碼實(shí)現(xiàn)AdapterViews和RecyclerView無(wú)限滾動(dòng)
這篇文章主要為大家詳細(xì)介紹了Android代碼實(shí)現(xiàn)AdapterViews和RecyclerView無(wú)限滾動(dòng)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07
Android入門之IntentService的使用教程詳解
IntentService的生命周期中有一個(gè)非常好的方法-onHandleIntent方法,它是一個(gè)abstract方法,開發(fā)者在實(shí)現(xiàn)IntentService時(shí)可以覆蓋它來處理“長(zhǎng)事務(wù)”。本文就來聊聊IntentService的使用,需要的可以參考一下2022-12-12
Android中的導(dǎo)航navigation的使用詳細(xì)步驟
在Android中,導(dǎo)航主要通過使用Navigation SDK來實(shí)現(xiàn),該SDK提供了一組工具和組件,可以幫助開發(fā)人員構(gòu)建具有一致性和可訪問性的用戶界面,這篇文章主要介紹了Android中的導(dǎo)航navigation的使用詳細(xì)步驟,需要的朋友可以參考下2024-04-04
Android實(shí)現(xiàn)將View轉(zhuǎn)化為圖片并保存到本地
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)將View轉(zhuǎn)化為圖片并保存到本地,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
Android Mms之:聯(lián)系人管理的應(yīng)用分析
本篇文章是對(duì)Android中的聯(lián)系人管理進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
Android開啟閃光燈的方法 Android打開手電筒功能
這篇文章主要為大家詳細(xì)介紹了Android開啟閃光燈的方法,Android打開手電筒功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Android實(shí)現(xiàn)頂部導(dǎo)航菜單左右滑動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)頂部導(dǎo)航菜單左右滑動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06
CDC與BG-CDC的含義電容觸控學(xué)習(xí)整理
今天小編就為大家分享一篇關(guān)于CDC與BG-CDC的含義電容觸控學(xué)習(xí)整理,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-12-12

