1. 首先在drawable文件夾定義一個shape.xml文件,內容如下:
成都創新互聯公司專注于網站建設,為客戶提供網站設計、網站制作、網頁設計開發服務,多年建網站服務經驗,各類網站都可以開發,品牌網站制作,公司官網,公司展示網站,網站設計,建網站費用,建網站多少錢,價格優惠,收費合理。
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#e6e6" />
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp" />
<padding
android:left="30dp"
android:top="0dp"
android:right="30dp"
android:bottom="0dp"
/>
</shape>
2. 在main.xml文件中,button使用這個shape.xml,如下:
<Button
android:id="@+id/button_next"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/button_next"
android:textSize="@dimen/label_text_size"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:gravity="center_horizontal|center_vertical"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/shape"
/>
這時,該button就顯示如shape.xml定義的形狀。
3. 在代碼中動態修改button 背景顏色,代碼如下:
GradientDrawable bgShape = (GradientDrawable)buttonNext.getBackground();
bgShape.setColor(Color.BLUE);
分享標題:Androidbutton,xml文件定義形狀,代碼中修改背景顏色
本文來源:http://vcdvsql.cn/article30/jhgopo.html
成都網站建設公司_創新互聯,為您提供品牌網站設計、做網站、網站收錄、網站制作、網站內鏈、網站改版
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯