日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android shape 按钮背景_Android button, xml文件定义形状,代码中修改背景颜色

發布時間:2023/12/19 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android shape 按钮背景_Android button, xml文件定义形状,代码中修改背景颜色 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 首先在drawable文件夾定義一個shape.xml文件,內容如下:

xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="rectangle">

android:topLeftRadius="10dp"

android:topRightRadius="10dp"

android:bottomRightRadius="10dp"

android:bottomLeftRadius="10dp" />

android:left="30dp"

android:top="0dp"

android:right="30dp"

android:bottom="0dp"

/>

2. 在main.xml文件中,button使用這個shape.xml,如下:

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);

總結

以上是生活随笔為你收集整理的android shape 按钮背景_Android button, xml文件定义形状,代码中修改背景颜色的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。