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)文章
Android自定義View之酷炫數(shù)字圓環(huán)
這篇文章主要為大家詳細(xì)介紹了Android自定義View之酷炫數(shù)字圓環(huán),實(shí)現(xiàn)效果很酷,,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-01-01Android獲取本機(jī)電話(huà)號(hào)碼的簡(jiǎn)單方法
Android獲取本機(jī)電話(huà)號(hào)碼的簡(jiǎn)單方法,需要的朋友可以參考一下2013-05-05Android Lottie實(shí)現(xiàn)中秋月餅變明月動(dòng)畫(huà)特效實(shí)例
Lottie是Airbnb開(kāi)源的一個(gè)支持 Android、iOS 以及 ReactNative,利用json文件的方式快速實(shí)現(xiàn)動(dòng)畫(huà)效果的庫(kù),下面這篇文章主要給大家介紹了關(guān)于Android Lottie實(shí)現(xiàn)中秋月餅變明月動(dòng)畫(huà)特效的相關(guān)資料,需要的朋友可以參考下2021-09-09Android實(shí)現(xiàn)網(wǎng)易嚴(yán)選標(biāo)簽欄滑動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)網(wǎng)易嚴(yán)選標(biāo)簽欄滑動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07Android 設(shè)置Edittext獲取焦點(diǎn)并彈出軟鍵盤(pán)
本文主要介紹了Android設(shè)置Edittext獲取焦點(diǎn)并彈出軟鍵盤(pán)的實(shí)現(xiàn)代碼。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04Android ListView構(gòu)建支持單選和多選的投票項(xiàng)目
如何在Android的ListView中構(gòu)建CheckBox和RadioButton列表?這篇文章主要為大家詳細(xì)介紹了Android ListView實(shí)現(xiàn)支持單選和多選的投票項(xiàng)目,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01Android自定義View圓形和拖動(dòng)圓跟隨手指拖動(dòng)
這篇文章主要介紹了Android自定義View圓形和拖動(dòng)圓跟隨手指拖動(dòng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11Android中AutoCompleteTextView與TextWatcher結(jié)合小實(shí)例
這篇文章主要為大家詳細(xì)介紹了Android中AutoCompleteTextView與TextWatcher結(jié)合的小實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05