Android圓角按鈕的制作方法
本文實例為大家分享了Android制作圓角按鈕的具體代碼,供大家參考,具體內(nèi)容如下
【主要步驟】
創(chuàng)建一個XML文件
以此文件作為Button的Background
1.創(chuàng)建XML文件
在res目錄下的drawable-mdpi下建立XML文件
button_frame_shape.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ffffff" /><!-- 填充的顏色 --> <!-- 設(shè)置按鈕的四個角為弧形 --> <!-- android:radius 弧形的半徑 --> <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp"/> <!-- 邊框粗細(xì)及顏色 --> <stroke android:width="2dp" android:color="@color/colorAccent" /> </shape>
2.使用
在Button下使用Android:background=”@drawable/button_frame_shape”
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/roundButton" android:text=" 圓角邊框按鈕 " android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_frame_shape" /> </LinearLayout>
效果如圖:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android中ViewPager獲取當(dāng)前顯示的Fragment
這篇文章主要介紹了Android中ViewPager獲取當(dāng)前顯示的Fragment的兩種方法,一種是使用 getSupportFragmentManager().findFragmentByTag()方法,另一種是重寫適配器的 setPrimaryItem()方法,有需要的朋友可以參考借鑒,下面來一起看看吧。2017-01-01Android應(yīng)用程序窗口(Activity)窗口對象(Window)創(chuàng)建指南
本文將詳細(xì)介紹Android應(yīng)用程序窗口(Activity)的窗口對象(Window)的創(chuàng)建過程,需要了解的朋友可以參考下2012-12-12Android開發(fā)中的ViewModel使用實戰(zhàn)案例
在Android應(yīng)用開發(fā)中,ViewModel作為架構(gòu)組件,重要的功能是管理UI數(shù)據(jù)與生命周期,文章深入分析ViewModel如何感知View的生命周期,以及其核心優(yōu)勢,包括生命周期感知、數(shù)據(jù)持久化和與UI層解耦,幫助開發(fā)者利用ViewModel優(yōu)化應(yīng)用架構(gòu),需要的朋友可以參考下2024-10-10