android xml實(shí)現(xiàn)按鈕的圓角、陰影效果及按下變化效果的實(shí)現(xiàn)代碼
前言
5個(gè)xml文件實(shí)現(xiàn) 按鈕的圓角、陰影效果以及按下變化效果
實(shí)現(xiàn)
drawable/shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 圓角 -->
<corners
android:radius="8dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"/><!-- 設(shè)置圓角半徑 -->
<!-- 間隔 -->
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/><!-- 各方向的間隔 -->
<!-- 大小 -->
<size
android:width="50dp"
android:height="50dp"/><!-- 寬度和高度 -->
<!-- 填充 -->
<solid
android:color=" #FF03A9F4"/><!-- 填充的顏色 -->
</shape>
drawable/shapepress.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 圓角 -->
<corners
android:radius="8dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"/><!-- 設(shè)置圓角半徑 -->
<!-- 間隔 -->
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/><!-- 各方向的間隔 -->
<!-- 大小 -->
<size
android:width="50dp"
android:height="50dp"/><!-- 寬度和高度 -->
<!-- 填充 -->
<solid
android:color="#FF7AD1F8"/><!-- 填充的顏色 -->
</shape>
drawable/shadow.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--第一層陰影-->
<item>
<shape android:shape="rectangle">
<solid android:color="#21000000" />
<corners android:radius="8dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp" />
<!-- 大小 -->
<size
android:width="50dp"
android:height="50dp"/><!-- 寬度和高度 -->
</shape>
</item>
<!--第二層前景-->
<item
android:bottom="2dp"
android:right="3dp"
android:drawable="@drawable/shape"
>
</item>
</layer-list>

drawable/shadowpress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--第一層陰影-->
<item>
<shape android:shape="rectangle">
<solid android:color="#0E000000" />
<corners android:radius="8dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp" />
<!-- 大小 -->
<size
android:width="50dp"
android:height="50dp"/><!-- 寬度和高度 -->
</shape>
</item>
<!--第二層前景-->
<!--第二層前景-->
<item
android:bottom="2dp"
android:right="3dp"
android:drawable="@drawable/shapepress"
>
</item>
</layer-list>

drawable/button_style.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--注意先后順序-->
<!-- 觸摸模式下單擊時(shí)的陰影-->
<item android:state_pressed="true" android:drawable="@drawable/shadowpress" />
<!-- 默認(rèn)時(shí)的背景圖片-->
<item android:drawable="@drawable/shadow" />
</selector>
activity_main.xml中引入
<Button android:id="@+id/button9" android:onClick="pushNumber" android:text="9" android:background="@drawable/button_style" android:textColor="@color/colorWhite" android:layout_margin="5dp" />

效果動(dòng)態(tài)圖

以上就是android xml實(shí)現(xiàn)按鈕的圓角、陰影效果以及按下變化效果的詳細(xì)內(nèi)容,更多關(guān)于android按鈕按下變化效果的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Android設(shè)置TextView首行縮進(jìn)示例代碼
使用過word的都會(huì)知道,在文字排版的時(shí)候經(jīng)常要設(shè)置首行縮進(jìn),這樣才會(huì)使排版更整齊,那么在Android中當(dāng)需要設(shè)置首行縮進(jìn)的時(shí)候該腫么辦呢,下面一起來看看。2016-08-08
Flutter使用?input?chip?標(biāo)簽組件示例詳解
這篇文章主要為大家介紹了Flutter使用?input?chip?標(biāo)簽組件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
Android下拉刷新控件SwipeRefreshLayout源碼解析
這篇文章主要為大家詳細(xì)解析Android下拉刷新控件SwipeRefreshLayout源碼,感興趣的小伙伴們可以參考一下2016-07-07
Android RxJava創(chuàng)建操作符Interval
這篇文章主要為大家詳細(xì)介紹了Android RxJava創(chuàng)建操作符Interval的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android實(shí)現(xiàn)毛玻璃效果的對(duì)話框
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)毛玻璃效果的對(duì)話框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
Android調(diào)用系統(tǒng)圖庫(kù)獲取圖片的方法
這篇文章主要為大家詳細(xì)介紹了Android調(diào)用系統(tǒng)圖庫(kù)獲取圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08
Android app開發(fā)中的Fragment入門學(xué)習(xí)教程
這篇文章主要介紹了Android app開發(fā)中的Fragment入門學(xué)習(xí)教程,包括Fragment的創(chuàng)建和XML布局文件中的Fragment定義等,需要的朋友可以參考下2016-02-02
Android開發(fā)經(jīng)驗(yàn)談:并發(fā)編程(線程與線程池)(推薦)
這篇文章主要介紹了Android開發(fā)經(jīng)驗(yàn)談:并發(fā)編程(線程與線程池),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04

