當前位置:首頁 » 安卓系統 » android按鈕的樣式

android按鈕的樣式

發布時間: 2025-01-28 06:39:01

Ⅰ 如何自定義android Button樣式

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

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

Ⅱ 如何自定義android Button樣式

返回博客列表
轉 android自定義button樣式

sumpower
發布時間: 2014/02/25 19:56

閱讀: 4162

收藏: 0

點贊: 0

評論: 0
摘要
android自定義button樣式

在Android開發應用中,默認的Button是由系統渲染和管理大小的。而我們看到的成功的移動應用,都是有著酷炫的外觀和使用體驗的。因此,我們在開發產品的時候,需要對默認按鈕進行美化。在本篇里,筆者結合在應用開發中的經驗,探討一下自定義背景的按鈕、自定義形狀按鈕的實現方法。
首先看實現效果截圖:

自定義背景的按鈕目前有2種方式實現,矢量和點陣圖。

1. 矢量圖形繪制的方式
矢量圖形繪制的方式實現簡單,適合對於按鈕形狀和圖案要求不高的場合。步驟如下:
(a) 使用xml定義一個圓角矩形,外圍輪廓線實線、內填充漸變色,xml代碼如下。
view plain
//bg_alibuybutton_default.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="地址">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFEC7600" />
<corners
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
</shape>
</item>
<item android:top="1px" android:bottom="1px" android:left="1px" android:right="1px">
<shape>
<gradient
android:startColor="#FFEC7600" android:endColor="#FFFED69E"
android:type="linear" android:angle="90"
android:centerX="0.5" android:centerY="0.5" />
<corners
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
</shape>
</item>
</layer-list>
同樣定義bg_alibuybutton_pressed.xml和bg_alibuybutton_selected.xml,內容相同,就是漸變顏色不同,用於按鈕按下後的背景變化效果。
(b) 定義按鈕按下後的效果變化描述文件drawable/bg_alibuybutton.xml,代碼如下。
view plain
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="地址">
<item android:state_pressed="true"
android:drawable="@drawable/bg_alibuybutton_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/bg_alibuybutton_selected" />
<item android:drawable="@drawable/bg_alibuybutton_default" />
</selector>
(c) 在你需要的界面定義文件中,如layout/main.xml中定義一個Button控制項。
view plain
<Button
android:layout_width="120dip"
android:layout_height="40dip"
android:text="矢量背景按鈕" android:background="@drawable/bg_alibuybutton" />
這樣,自定義背景的按鈕就可以使用了,在實現onClick方法後就可以響應操作。

Ⅲ 安卓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"/>
熱點內容
iisftpwin10 發布:2025-03-18 20:27:50 瀏覽:954
mysql執行存儲過程語句 發布:2025-03-18 20:13:00 瀏覽:956
android控制項移動 發布:2025-03-18 20:05:29 瀏覽:700
新東方課程緩存路徑 發布:2025-03-18 20:00:20 瀏覽:85
登錄一個新ip的伺服器怎麼登錄 發布:2025-03-18 19:49:13 瀏覽:961
戶戶通遙控器隱藏密碼多少 發布:2025-03-18 19:43:23 瀏覽:196
erlang資料庫 發布:2025-03-18 19:35:17 瀏覽:647
華碩手機配置及價格如何 發布:2025-03-18 19:34:34 瀏覽:582
安卓模擬器埠號怎麼查 發布:2025-03-18 19:34:19 瀏覽:760
新建文件夾mp4magnet 發布:2025-03-18 19:34:17 瀏覽:933