當前位置:首頁 » 安卓系統 » android中button

android中button

發布時間: 2023-08-14 04:57:01

① android中button有幾種狀態

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

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

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

② 如何在android當中實現Button操作

你可以現在布局文件layout中添加button控制項,然後對其屬性設置,最後在src文件中,編寫java文件,對該按鈕的功能進行設置,並監聽按鈕事件

③ Android實踐6 | 實現Button的監聽

按鈕是最常用的控制項,通過onClick方法可以實現單擊按鈕後產生一定的操作。可以傳遞intent,也可顯示提示信息。

1、學會重載setOnClickListener方法,進行按鈕的監聽處理
2、Toast的使用

1、單按鈕監聽
1)、在按鈕所屬的父Activity里,創建按鈕變數
private Button mBtnTextView;
2)、在onCreate方法內部,變數關聯資源id
mBtnTextView = (Button) findViewById(R.id.btn_tv);
3)、在onCreate方法內部,設置setOnClickListener

2、多按鈕監聽
1)、在按鈕所屬的父Activity里,創建多個按鈕變數,和Intent變數

2)、在onCreate方法內部,變數關聯資源id

3)、在onCreate方法內部,設置setOnClickListener

4),在按鈕所屬的父Activity里,創建公共的ButtonListener監聽類

可通過傳入Button的Id switch語句進行選擇 進行監聽 實現不同的操作

要點:
1、findViewById方法關聯資源里的按鈕id。
2、重載View.OnClickListener方法。
3、使用的單擊後啟動操作都在onClick方法里。
getId()方法取得按鈕的id,確定是那一個按鈕被單擊。
4、Toast英文含義是吐司,在Android中,它就像烘烤機里做好的吐司彈出來,並持續一小段時間後慢慢消失。
1)、makeText方法
2)、show()方法
如:

④ 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有幾種狀態

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

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

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

熱點內容
滑板鞋腳本視頻 發布:2025-02-02 09:48:54 瀏覽:433
群暉怎麼玩安卓模擬器 發布:2025-02-02 09:45:23 瀏覽:557
三星安卓12彩蛋怎麼玩 發布:2025-02-02 09:44:39 瀏覽:744
電腦顯示連接伺服器錯誤 發布:2025-02-02 09:24:10 瀏覽:537
瑞芯微開發板編譯 發布:2025-02-02 09:22:54 瀏覽:147
linux虛擬機用gcc編譯時顯示錯誤 發布:2025-02-02 09:14:01 瀏覽:240
java駝峰 發布:2025-02-02 09:13:26 瀏覽:652
魔獸腳本怎麼用 發布:2025-02-02 09:10:28 瀏覽:538
linuxadobe 發布:2025-02-02 09:09:43 瀏覽:212
sql2000資料庫連接 發布:2025-02-02 09:09:43 瀏覽:726