Android實(shí)現(xiàn)圓角Button按鈕
本文實(shí)例講述了Android開發(fā)圓角Button按鈕實(shí)現(xiàn)過程,分享給大家供大家參考,具體內(nèi)容如下
需求及效果圖:

實(shí)現(xiàn)思路:
1、shape實(shí)現(xiàn)圓角
在drawable新建兩個xml 文件, 這兩個 xml文件用shape 實(shí)現(xiàn)了圓角效果。
Note:
因?yàn)橐層脩粲邪聪氯サ男Чw驗(yàn), 所有要有兩套圓角圖, 在按下去時候切換
<!-- res/drawable/button_shape_normal.xml --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- rounded corner --> <corners android:radius="5dp" /> <solid android:color="@color/orange_normal" /> </shape>
<!-- res/drawable/button_shape_pressed.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- rounded corner -->
<corners android:radius="5dp" />
<!-- fill with two colors, and the two colors change softly -->
<!--
<gradient
android:angle="270"
android:startColor="@color/orange_light"
android:endColor="@color/orange_normal"
android:useLevel="true" />
-->
<solid android:color="@color/orange_light" />
</shape>
2、selector實(shí)現(xiàn)按下效果
在 drawable 新建 一個 xml 文件, 用 selector 把剛才 建立的兩個 xml 文件組織起來
<!-- res/drawable/button_shape.xml --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_shape_normal" android:state_pressed="false"/> <item android:drawable="@drawable/button_shape_pressed" android:state_pressed="true"/> </selector>
3、style實(shí)現(xiàn)多個按鈕復(fù)用
在res/values/styles.xml 里面輸入下面代碼
<style name="SmsButton">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">20sp</item>
<item name="android:background">@drawable/button_shape</item>
<item name="android:textColor">@color/white</item>
</style>
4、引用圓角按鈕
在 layout/fragment_bomb.xml 里面 用 style 引用
<Button
android:id="@+id/fireup"
style="@style/SmsButton"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:text="@string/fireup" />
可以省去建立style的步驟, 直接在layout里面引用即可。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)Android有所幫助。
相關(guān)文章
Android獲取當(dāng)前應(yīng)用分配的最大內(nèi)存和目前使用內(nèi)存的方法
今天小編就為大家分享一篇關(guān)于Android獲取當(dāng)前應(yīng)用分配的最大內(nèi)存和目前使用內(nèi)存的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02
Android開發(fā)ThreadPoolExecutor與自定義線程池詳解
這篇文章主要為大家介紹了Android開發(fā)ThreadPoolExecutor與自定義線程池詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
Android實(shí)現(xiàn)動態(tài)自動匹配輸入內(nèi)容
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)動態(tài)自動匹配輸入內(nèi)容,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08
Android屏幕旋轉(zhuǎn)之橫屏豎屏切換的實(shí)現(xiàn)
這篇文章主要介紹了Android屏幕旋轉(zhuǎn)之橫屏豎屏切換的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
android 開發(fā)教程之日歷項(xiàng)目實(shí)踐(二)
決定開始學(xué)習(xí) Android 平臺下的軟件開發(fā),以日歷作為實(shí)踐項(xiàng)目,進(jìn)行一周后,基本完成,有需要的朋友可以參考下2013-01-01
微前端架構(gòu)ModuleFederationPlugin源碼解析
這篇文章主要為大家介紹了微前端架構(gòu)ModuleFederationPlugin源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
關(guān)于android studio升級4.1 某些插件使用不了的問題(Mac)
這篇文章主要介紹了關(guān)于android studio升級4.1 某些插件使用不了的問題(Mac),本文給大家分享解決方法供大家參考,感興趣的朋友跟隨小編一起看看吧2020-10-10
Android多點(diǎn)觸控技術(shù)實(shí)戰(zhàn) 針對圖片自由縮放和移動
這篇文章主要為大家詳細(xì)介紹了Android多點(diǎn)觸控技術(shù)實(shí)戰(zhàn),自由地對圖片進(jìn)行縮放和移動,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10

