當前位置:首頁 » 安卓系統 » androidbtn

androidbtn

發布時間: 2023-03-16 23:00:08

『壹』 android,btn.setEnabled(true);///// btn定義為了final,這里哪個類是內部類或者匿名內部類呢

java">newOnCheckedChangeListener(){
@Override
publicvoidonCheckedChanged(CompoundButtonbuttonView,
booleanisChecked){///這是方法呀
//TODOAuto-generatedmethodstub
if(isChecked)
btn.setEnabled(true);/////btn定義為了final,可是哪個類是內部類或者匿名內部類呢??
else
btn.setEnabled(false);
}
}

這個整體是一個實現了OnCheckedChangeListener介面的匿名類。在創建時,作為new語句的一部分來聲明匿名類,如下所示: new <類或介面> <類的主體> 這種形式的new語句聲明一個新的匿名類,它對一者粗埋個給定凳唯的類進行擴展,或者實現一個給定的介面。它還創建那個類的一個新實例,並把它作為語句的結果而首螞返回。

『貳』 android 怎麼把button變成圓形

使用shape,請看下面截圖,例子來自於android學習手冊,360手機助手中下載,裡面有108個例子、源碼還有文檔。



<?xml version="1.0" encoding="utf-8"?>

<shape

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

android:shape="oval">

<!-- 填充的顏色 -->

<solid android:color="#FFFFFF"/>

<!-- 設置按鈕的四個角為弧形 -->

<!-- android:radius 弧形的半徑 -->

<corners android:radius="360dip"/>

<!-- padding: Button 裡面的文字與Button邊界的間隔 -->

<padding

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp"

/>

</shape>

-----Main layout文件

<?xml version="1.0" encoding="utf-8"?>

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

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/soft_info"

/>

<!—直接設置背景 -->

<Button

android:id="@+id/roundBtn1"

android:background="@drawable/btn_oval"

android:layout_width="50dip"

android:layout_height="50dip"

/>

<!— 調用shape自定義xml文件 -->

<Button

android:id="@+id/roundBtn"

android:text="橢圓按鈕"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/main_menu_btnshape"

/>

</LinearLayout>

----acitivity文件

public class MyLifeActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

}

『叄』 android button上的字怎麼水平居中

在button的xml中增加 android:gravity="center"即可實現文字水平居中。

Android中控制項的居中有以下設置方式:

  1. xml代碼當中:android:layout_gravity="center"

  2. xml代碼當中: android:gravity="center"

取值可選:

  1. center_vertical表示上下居中

  2. center_horizontal表示左右居中

  3. center表示水平居中

  4. android:layout_gravity 表示當前控制項相對某個控制項的居中方式,gravity表示當前控制項的子控制項居中方式。

『肆』 android button中的字如何居中

設置android:gravity="center"進行字居中。
android:gravity:針對控制項里的元素來說的,用來控制元素在該控制項里的顯示位置。
屬性值有top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。

『伍』 android 中怎麼為button設置監聽

android 中為button設置監聽的方法是:

1、匿名內部類作為事件監聽類

<spanstyle="font-size:14px;">Buttonbutton=(Button)findViewById(R.id.button);

button.setOnClickListener(newOnClickListener(){

攜漏@Override

publicvoidonClick(View遲缺v){

System.out.println("匿名內部類作為事件監辯旦爛聽器");

}

});</span>

2、內部類作為監聽器

『陸』 android button什麼情況下會獲得焦點

android中,要使控旁租件獲得焦點,需要伍返先setFocus,再requestFocus。
以Button為例:
btn.setFocusable(true);
btn.setFocusableInTouchMode(true);
btn.requestFocus();
btn.requestFocusFromTouch();

//獲得失去焦腔啟飢點的監聽器
btn.setOnFocusChangeListener(new OnFocusChangeListener() {

@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if (hasFocus) {
btn_box.setBackgroundResource(R.drawable.book_green);
}else {
btn_box.setBackgroundResource(R.drawable.book);
}
}
});

『柒』 android開發中button按鈕不起作用,btn不響應點擊事件,檢查沒有發現代碼的問題。

你既然已經 findViewById了你的button了,你又去實例化一個btn,那這樣你的btn其實是你new的那個,但是你在你的Activity上看到的是你findViewById的那個Button,你new的btn由於你沒設置他的位置,所以你看不到!

熱點內容
預編譯頭子目錄 發布:2025-05-09 23:05:39 瀏覽:174
出軌資料庫 發布:2025-05-09 22:48:47 瀏覽:148
java過濾器的作用 發布:2025-05-09 22:44:06 瀏覽:857
定投策略演算法 發布:2025-05-09 22:21:36 瀏覽:601
梯形糾正演算法 發布:2025-05-09 22:16:46 瀏覽:717
解壓心跳聲 發布:2025-05-09 22:16:10 瀏覽:718
如何取消安卓手機程序隱私密碼 發布:2025-05-09 21:48:03 瀏覽:48
c語言字元串數組連接 發布:2025-05-09 21:46:37 瀏覽:133
源碼的移碼 發布:2025-05-09 21:25:01 瀏覽:754
ie內核緩存 發布:2025-05-09 21:19:35 瀏覽:545