android自定義形狀的按鍵實(shí)例代碼
步驟:
1.在drawable 文件夾中創(chuàng)建一個(gè)xml布局文件。
2.修改布局文件
3.在需要使用背景的按鍵中導(dǎo)入布局。
創(chuàng)建布局文件:

修改布局文件:
<?xml version="1.0" encoding="utf-8"?>
<!--shape:形狀 rectangle 長(zhǎng)方形-->
<!--corners 邊角-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--設(shè)置背景顏色-->
<solid android:color="@color/colorblue"/>
<!--設(shè)置角為半圓 radius 半徑-->
<corners android:radius="10dp"/>
<!--bottom 下 top 上 left左 right右-->
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp"
/>
</shape>
預(yù)覽效果圖:

在按鍵中添加布局:

實(shí)際效果:

PS(橢圓按鍵的xml):
<?xml version="1.0" encoding="utf-8"?>
<!-- shape 形狀 oval橢圓形-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<!--設(shè)置背景顏色-->
<solid android:color="@color/colorgreen"/>
<!--設(shè)置高度和寬度-->
<size android:height="30dp"
android:width="120dp"/>
<padding
android:bottom="10dp"
android:top="10dp"
android:left="10dp"
android:right="10dp"/>
</shape>
總結(jié)
以上所述是小編給大家介紹的android自定義形狀的按鍵實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Android仿微信實(shí)現(xiàn)首字母導(dǎo)航條
這篇文章主要為大家詳細(xì)介紹了Android仿微信實(shí)現(xiàn)首字母導(dǎo)航條的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08
Android開(kāi)發(fā)者必備的十個(gè)工具介紹
這篇文章主要介紹了Android開(kāi)發(fā)者必備的十個(gè)工具介紹,在這篇文章中,討論了10個(gè)最常見(jiàn)的工具,android 開(kāi)發(fā)者應(yīng)該了解和學(xué)習(xí)使用,需要的朋友可以參考下2015-03-03
Android編程實(shí)現(xiàn)計(jì)算兩個(gè)日期之間天數(shù)并打印所有日期的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)計(jì)算兩個(gè)日期之間天數(shù)并打印所有日期的方法,涉及Android日期時(shí)間相關(guān)轉(zhuǎn)換與運(yùn)算操作技巧,需要的朋友可以參考下2018-01-01
Android編程實(shí)現(xiàn)自定義控件的方法示例
這篇文章主要介紹了Android編程實(shí)現(xiàn)自定義控件的方法,結(jié)合實(shí)例形式分析了Android自定義控件的布局、功能實(shí)現(xiàn)與使用技巧,需要的朋友可以參考下2017-06-06
Android實(shí)現(xiàn)listview滑動(dòng)時(shí)漸隱漸現(xiàn)頂部欄實(shí)例代碼
android中實(shí)現(xiàn)listview滑動(dòng)時(shí)漸隱漸現(xiàn)頂部欄只是在獲取listview的滑動(dòng)距離上可能沒(méi)法直接獲取,需要?jiǎng)討B(tài)的去計(jì)算。感興趣的朋友一起看看吧2016-10-10
利用Kotlin如何實(shí)現(xiàn)Android開(kāi)發(fā)中的Parcelable詳解
這篇文章主要給大家介紹了關(guān)于利用Kotlin如何實(shí)現(xiàn)Android開(kāi)發(fā)中的Parcelable的相關(guān)資料,并且給大家介紹了關(guān)于Kotlin使用parcelable出現(xiàn):BadParcelableException: Parcelable protocol requires a Parcelable.Creator...問(wèn)題的解決方法,需要的朋友可以參考下。2017-12-12

