當前位置:首頁 » 安卓系統 » androidbutton的樣式

androidbutton的樣式

發布時間: 2022-06-28 19:05:30

① android中button有幾種狀態

Android中,button按鈕通常有三個狀態:

1. normal(正常狀態);
2. focus(焦點狀態);
3. pressed(按下狀態)
4. selected(選中狀態)

注意:按下後未松開前是pressed,表示按下。
松開後當前項目獲得焦點,是focused。
focused的項只有一個,selected是當選中該按鈕時顯示的狀態。

② android怎麼改變button中字體的格式

使用方法 第一種是在listview中配置android:listSelector=」@drawable/list_item_bg」 第二種是在listview的item中添加屬性android:background=」@drawable/list_item_bg」 第三種是java代碼中使用: Drawable drawable = getResources()/apk/res/android">" target="_blank">schemas/apk/res/android"></a> <item android:state_selected="true" android:color="#FF0000" /> <item android:state_focused="true" android:color="#00FF00" /> <item android:state_pressed="true" android:color="#0000FF" /> <item android:color="#000000" /></selector>使用方法 android:textColor="@drawable/button_color" 更復雜的效果 還可以實現更復雜的效果,例如漸變等等。 drawable/button_color/apk/res/android">" target="_blank">schemas/apk/res/android"></a> <item android:state_pressed="true"> <!-- 定義當button 處於pressed 狀態時的形態。--> <shape> <gradient android:startColor="#8600ff" /> <stroke android:width="2dp" android:color="#000000" /> <corners android:radius="5dp" /> <padding android:left="10dp" android:top="10dp" android:bottom="10dp" android:right="10dp"/> </shape> </item> <item android:state_focused="true"> <!-- 定義當button獲得 focus時的形態 --> <shape> <gradient android:startColor="#eac100"/> <stroke android:width="2dp" android:color="#333333" color="#ffffff"/> <corners android:radius="8dp" /> <padding android:left="10dp" android:top="10dp" android:bottom="10dp" android:right="10dp"/> </shape> </item></selector>使用方法 android:background="@drawable/button_color" android:focusable="true"

③ 安卓UI自定義radiobutton樣式

自定義RadioButton樣式分為兩步:

1、自定義好樣式:

打開style.xml,添加一個item

<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 button disable 樣式問題

安卓系統從selector文件里找匹配項的時候是從上往下找的,找到第一個符合的就不再往下走了,你的第一個Item什麼也沒寫,表示符合任務狀態。你可以把你的兩個item換下順序試試。

⑤ android 怎麼讓button按鈕樣式改變

<Button style="@android:style/Widget.ImageButton"//引用系統樣式 android:layout_width="wrap_content" android:layout_height="wrap_content" />

⑥ 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樣式

主要有2種方式進行自定義android button 的樣式。

【主要方式】

  1. 自定義button樣式。

  2. 自定義style樣式。


【原理】

通過android sdk提供的方案進行自定義相關的android button的樣式。

【詳細實現步奏】

1.自定義button樣式

主要是通過自定義背景圖或者通過自定義selector的方式形成button的樣式效果。

1.1圖片的方式:

<?xmlversion="1.0"encoding="utf-8"?>
<selectorxmlns:android="http://schemas.android.com/apk/res/android">
<itemandroid:state_pressed="true"android:drawable="@drawable/a1";/>
<itemandroid:state_focused="true"android:drawable="@drawable/a2";/>
<itemandroid:drawable="@drawable/a1";/>
</selector>

xm布局文件使用

<Buttonandroid:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_style">
</Button>

1.2 自定義selector的方式,selector 種使用以下屬性進行自定義自己所需要的按鈕樣式。

gradient 主體漸變,startColor開始顏色,endColor結束顏色 , angle開始漸變的角度(值只能為90的倍數,0時為左到右漸變,90時為下到上漸變,依次逆時針類推) stroke 邊框 width 邊框寬度,color 邊框顏色, corners 圓角 radius 半徑,0為直角, padding text值的相對位置。

2.自定義style樣式

如下樣式:

<resourcesxmlns:android="http://schemas.android.com/apk/res/android">
<stylename="AppBaseTheme"parent="android:Theme.Light">
</style>
<stylename="AppTheme"parent="AppBaseTheme">
</style>
<stylename="btnStyle">
<itemname="android:textSize">30px</item>
<itemname="android:width">15px</item>
<itemname="android:height">15px</item>
</style>
</resources>

xml文件中引用

<Button
style="@style/btnStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"/>

【最後】

2種方式組合使用效果更佳,效率更高,修改方便。

⑧ android button 樣式怎麼寫

如何自定義android Button樣式

android自帶的樣式比較難看,如何能夠自定義按鈕的樣式,使其顯示的跟美工設計的效果一樣,現與大家分享下

工具/原料

eclipse ADT

方法/步驟

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

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

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

下圖是在button中調用自定義樣式的方法,比較簡單

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

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

出自:http://jingyan..com/article/454316ab4bdc66f7a7c03a13.html

⑨ android studio的button在點擊時,點擊後樣式

Button只能實現按下去的時候的變化, 但是松開手就會恢復, 如果你想按下去變化一下一直保持, 那你就要用 checkBox 這類形的開關控制項, 因為它們都有一個狀態 isChecked true時表示一個, false表示另外一個, 可以用 selector來實現的.

熱點內容
卸載oracle資料庫 發布:2024-04-23 20:36:26 瀏覽:520
發帖站源碼 發布:2024-04-23 20:22:45 瀏覽:681
小豚攝像頭存儲卡滿了怎麼辦 發布:2024-04-23 20:04:41 瀏覽:231
我的世界伺服器管理應該做什麼 發布:2024-04-23 19:37:19 瀏覽:146
伺服器是如何處理多個用戶的請求 發布:2024-04-23 19:35:26 瀏覽:957
寫安卓用什麼架構 發布:2024-04-23 18:51:14 瀏覽:413
安卓r11是什麼介面 發布:2024-04-23 18:42:51 瀏覽:762
公元紀年法的演算法 發布:2024-04-23 18:38:25 瀏覽:113
遠景s1什麼配置 發布:2024-04-23 18:12:11 瀏覽:498
系統程序媒體存儲設備 發布:2024-04-23 18:12:09 瀏覽:822