Android開發(fā)實現(xiàn)的圓角按鈕、文字陰影按鈕效果示例
本文實例講述了Android開發(fā)實現(xiàn)的圓角按鈕、文字陰影按鈕效果。分享給大家供大家參考,具體如下:
效果圖:
如果要實現(xiàn)圓角圖片,并變色須在drawable中配置背景文件如下:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 圓角深紅色按鈕 --> <solid android:color="@color/RED"/> <corners android:radius="15dip"/> </shape> </item> <item android:state_pressed="false"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 圓角紅色按鈕 --> <solid android:color="@color/PURPLE"/> <corners android:radius="15dip"/> </shape> </item> </selector>
三個按鈕整體布局文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!--文字帶陰影的按鈕--> <!--陰影模糊程度:android:shadowRadius="5"--> <!--陰影與文字的距離:android:shadowDx="20"--> <!--android:shadowDy="20"--> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="文字帶陰影的按鈕" android:textSize="20pt" android:shadowColor="#aa5" android:shadowRadius="5" android:shadowDx="20" android:shadowDy="20"/> <!--普通文字按鈕--> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#836622" android:text="普通按鈕" android:textSize="20pt"/> <!--帶文字的圖片按鈕--> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_selector" android:textSize="20px" android:text="帶文字的按鈕"/> </LinearLayout>
顏色RED和PURPLE的宏定義:
<color name="RED" >#ff0000</color> <color name="PURPLE" >#9a32cd</color>
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》及《Android資源操作技巧匯總》
希望本文所述對大家Android程序設計有所幫助。
相關(guān)文章
Android之ListView分頁加載數(shù)據(jù)功能實現(xiàn)代碼
這篇文章主要為大家詳細介紹了Android之ListView分頁加載數(shù)據(jù)功能實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08Android?Banner本地和網(wǎng)絡輪播圖使用介紹
大家好,本篇文章講的是Android?Banner本地和網(wǎng)絡輪播圖使用介紹,感興趣的同學趕快來看一看吧,希望本篇文章對你起到幫助2021-11-11Android Studio中通過CMake使用NDK并編譯自定義庫和添加預編譯庫
這篇文章是基于Android Studio 3.01版本的,NDK是R16。本文重點給大家介紹Android Studio中通過CMake使用NDK并編譯自定義庫和添加預編譯庫的相關(guān)知識,感興趣的朋友一起看看吧2018-01-01Gradle?Build?Cache引發(fā)的Task緩存編譯問題
這篇文章主要為大家介紹了Gradle?Build?Cache引發(fā)的Task緩存編譯問題,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06Android基于方法池與回調(diào)實現(xiàn)登錄攔截的場景
這篇文章主要為大家介紹了Android基于方法池與回調(diào)實現(xiàn)登錄攔截的場景詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-08-08Android RecyclerView詳解之實現(xiàn) ListView GridView瀑布流效果
RecyclerView 是Android L版本中新添加的一個用來取代ListView的SDK,它的靈活性與可替代性比listview更好2016-07-07