當前位置:首頁 » 安卓系統 » 安卓按鈕樣式在哪裡

安卓按鈕樣式在哪裡

發布時間: 2023-07-01 15:58:04

Ⅰ 安卓UI自定義radiobutton樣式

自定義RadioButton樣式分為兩步:

1、自定義好樣式:

打開style.xml,添加一個item

java"><stylename="RadiobuttonStyle">
<itemname="android:gravity">center</item>
<itemname="android:textSize">16sp</item>
<itemname="android:textColor">@color/text_select_color</item>
<itemname="android:button">@null</item>
<itemname="android:drawableTop">@drawable/select_rbtn_home</item>
</style>

2、在RadioButon中引用:

<RadioButton
android:id="@+id/tv_tab_home"
style="@style/RadiobuttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/tab_home"/>

Ⅱ android studio中的button有哪些方法

先介紹下修改原理:首先打開位於android.widget包下面的Button.java文件,這里有一句關鍵的代碼如下:
public
Button(Context
context,
AttributeSet
attrs)
{
this(context,
attrs,
com.android.internal.R.attr.buttonStyle);
}
1
2
3
其中com.android.internal.R.attr.buttonStyle就是我們修改樣式的關鍵了,網上的教程的修改方法大都是:
<Button
style="@style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1"
android:text="價格"
/>
1
2
3
4
5
6
也就是在對應的xml裡面button控制項裡面編寫style達到目的。
但是如果我們的app需要完全統一整個應用的button的樣式,那麼就需要在每一個button裡面添加style。
這顯然效率太低下了。
接下來打開我們項目中values文件夾下面的styles.xml文件,我們創建安卓項目的時候,會有一個默認的styles文件。
打開之後找到這段代碼:
<style
name="AppBaseTheme"
parent="Theme.Holo.Light">
<!--
Theme
customizations
available
in
newer
API
levels
can
go
in
res/values-vXX/styles.xml,
while
customizations
related
to
backward-compatibility
can
go
here.
-->
</style>
<!--
Application
theme.
-->
<style
name="AppTheme"
parent="AppBaseTheme">
1
2
3
4
5
6
7
8
9
10
不保證讀者的默認styles.xml和我的是一樣的,不過大概是這個樣子,有可能讀者的最低支持是2.3、那麼就沒有Them.Light。
我們使用eclipse的快捷鍵打開這個Theme.Holo.Light。可以看到如下代碼:
<style
name="Theme.Holo.Light"
parent="Theme.Light">
<item
name="colorForeground">@android:color/bright_foreground_holo_light</item>
<item
name="colorForegroundInverse">@android:color/bright_foreground_inverse_holo_light</item>
<item
name="colorBackground">@android:color/background_holo_light</item>
<item
name="colorBackgroundCacheHint">@android:drawable/background_cache_hint_selector_holo_light</item>
<item
name="disabledAlpha">0.5</item>
<item
name="backgroundDimAmount">0.6</item>

Ⅲ 如何自定義android Button樣式

在windows7操作系統Android studio中按照如下方法定義button的樣式。

1、首先使用Android studio創建一個項目,項目結構如下:

Ⅳ 怎樣設置button的默認樣式

設置button的默認樣式的方法

  • 在layout中添加2個按鈕,從下圖中可以看出在按鈕中調用了style和android:background屬性,這兩個屬性一個是自定義樣式,一個是給按鈕添加背景圖片,下面詳細介紹下

  • 步驟閱讀.2展開res目錄,可以看到在values目錄下有styles.xml文件,該文件用於自定義樣式,雙擊打開

  • 步驟閱讀.3下圖中標注的是我自定義的樣式,name為BtnStyle,當按鈕調用自定義樣式的時候訪問這個name

  • 步驟閱讀.4下圖是在button中調用自定義樣式的方法,比較簡單

  • 步驟閱讀.5下面分享下如何往按鈕中添加自定義圖片,使按鈕看起來更漂亮些,因不同手機解析度不同,那必然牽扯到圖片的拉伸,在android系統下有個很好的技術「九宮格「,可以對圖片進行處理,只對局部進行拉伸,給工具目錄存儲在androidsdk oolsdraw9patch.bat,經過該工具處理的圖片以.9.png結尾,放到drawable文件夾中

  • 步驟閱讀.6下圖是在Button中通過android:background屬性載入圖片的方法,至此我們自定義的按鈕樣式也就完成了,當然這只是個引子,在具體的項目工程中實現的效果要比這個demo復雜很多,有好的設計思路歡迎交流。

Ⅳ 如何自定義android Button樣式

親,可以用到Drawable中的shape哦,給你一個demo

<?xmlversion="1.0"encoding="utf-8"?>
<selectorxmlns:android="

<itemandroid:state_focused="false">
<shape>
<solidandroid:color="@color/find_passwordbar_bg"/>
<strokeandroid:width="0.5dp"android:color="#C8C8C8"/>
</shape>
</item>

<itemandroid:state_focused="true">
<shape>
<solidandroid:color="@color/find_passwordbar_bg"/>
<strokeandroid:width="0.5dp"android:color="@color/main_color"/>
</shape>
</item>

</selector>

各個屬性的介紹

solid:實心,就是填充的意思
android:color指定填充的顏色

gradient:漸變
android:startColor和android:endColor分別為起始和結束顏色,ndroid:angle是漸變角度,必須為45的整數倍。
另外漸變默認的模式為android:type="linear",即線性漸變,可以指定漸變為徑向漸變,android:type="radial",徑向漸變需要指定半徑android:gradientRadius="50"。

stroke:描邊
android:width="2dp"描邊的寬度,android:color描邊的顏色。
我們還可以把描邊弄成虛線的形式,設置方式為:
android:dashWidth="5dp"
android:dashGap="3dp"
其中android:dashWidth表示'-'這樣一個橫線的寬度,android:dashGap表示之間隔開的距離。

corners:圓角
android:radius為角的弧度,值越大角越圓。
我們還可以把四個角設定成不同的角度,方法為:
<corners
android:topRightRadius="20dp"右上角
android:bottomLeftRadius="20dp"右下角
android:topLeftRadius="1dp"左上角
android:bottomRightRadius="0dp"左下角
/>

我自己寫的一個按鈕,效果就像圖中所示,用的Shape



新建後存放位置在res/drawable下


希望能幫到你,還望採納

熱點內容
逃離塔科夫啟動器選什麼伺服器 發布:2025-02-06 21:44:48 瀏覽:291
我的世界手機版伺服器開服教程 發布:2025-02-06 21:43:01 瀏覽:271
微信娛樂源碼 發布:2025-02-06 21:34:53 瀏覽:529
編譯翻譯運行 發布:2025-02-06 21:05:20 瀏覽:200
安卓源碼版本 發布:2025-02-06 20:51:34 瀏覽:432
安卓系統網路播放器哪個好 發布:2025-02-06 20:42:02 瀏覽:818
頭條緩存的視頻格式 發布:2025-02-06 20:32:18 瀏覽:116
ftp不顯示文件夾 發布:2025-02-06 20:30:37 瀏覽:127
蘋果手機解壓怎麼打開 發布:2025-02-06 20:29:35 瀏覽:476
單片機程序存儲器 發布:2025-02-06 20:29:31 瀏覽:209