當前位置:首頁 » 安卓系統 » androidbutton控制項

androidbutton控制項

發布時間: 2023-06-11 10:44:42

Ⅰ android 中button控制項都有些什麼常用的屬性

<Button
android:id="@+id/loginButton"
android:layout_width="50dp
android:layout_height="@dimen/button_footer_height"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:text="Login"
android:textSize="12dp"
android:visibility="invisible" />
我用到這些

Ⅱ Android-RadioButton單選按鈕控制項詳解

RadioButton是單選按鈕,允許用戶在一個組中選擇一個選項。同一組中的單選按鈕有互斥效果。

1.RadioButton是圓形單選框;
2.RadioGroup是個可以容納多個RadioButton的容器;
3.在RadioGroup中的RadioButton控制項可以有多個,但同時有且僅有一個可以被選中。

基本的使用就是上面Demo說的那樣。在Android開發當中,我們也可以使用RadioButton控制項來實現應用的底部導航欄。

Ⅲ android 怎樣讓兩個button控制項挨在一起,左右對齊 沒有距離

Android中兩個Button可以使用線性布局LinearLayout來包含。

控制項之間的間距有兩種設置:

  1. android:layout_margin="10dp" 外邊距

  2. android:padding="10dp" 內邊距

在Button中將android:layout_margin="0dp" android:padding="0dp"

即將內外兩個間距都設置為0即可

Ⅳ android中button上設置圖片

android中button上設置圖片的方法為:
1、自定義MyButton類
public class MyButton extends Button {
//This constructormust be
public MyButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyButton(Context context) {
super(context);
}
private Paint mPaint = null;
private String mText;
private int mX, mY;
public void onSetText(String text, int nLeft, int nBottom, int nTextSize,
int nTextColor) {
mPaint = new Paint();
mPaint.setTextSize(nTextSize);
mPaint.setColor(nTextColor);
this.mText = text;
this.mX = nLeft;
this.mY = nBottom;
}
private int mDownBmpId, mUpBmpId;
public void onSetBmp(int nDownID, int nUpID) {
this.mDownBmpId = nDownID;
this.mUpBmpId = nUpID;
}
@Override
public void onDraw(Canvas canvas) {
if (mPaint != null)
canvas.drawText(mText, mX, mY, mPaint);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
super.setBackgroundResource(mDownBmpId);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
super.setBackgroundResource(mUpBmpId);
}
return super.onTouchEvent(event);
}
}

2、 在xml布局文件中添加MyButton控制項,像應用普通的Button控制項一樣。
<com.MyButton
android:id="@+id/test_btn" android:layout_width="120px"
android:layout_height="fill_parent" android:text="Test"
android:background="@drawable/btn_u" />
其中com.MyButton是你定義的MyButton類所在的包名
3、在onCreate()中載入MyButton控制項。
MyButton btn = (MyButton)findViewById(R.id.test_btn);
btn.onSetBmp(R.drawable.btn_d, R.drawable.btn_u);
其中btn_d表示為按下btn時背景圖片,btn_u為默認狀態下btn背景圖片。

熱點內容
dhcp伺服器租用其IP地址 發布:2025-08-23 09:02:33 瀏覽:5
android列印時間 發布:2025-08-23 09:02:32 瀏覽:374
p30哪個配置銷量大 發布:2025-08-23 08:53:10 瀏覽:914
liunxsvn創建文件夾 發布:2025-08-23 08:23:11 瀏覽:739
日文解壓 發布:2025-08-23 08:02:24 瀏覽:629
街籃二蘋果怎麼和安卓玩游戲 發布:2025-08-23 07:56:47 瀏覽:64
linuxh3c 發布:2025-08-23 07:39:25 瀏覽:159
免費電腦主機伺服器 發布:2025-08-23 07:39:21 瀏覽:596
js是解釋執行還是編譯執行 發布:2025-08-23 07:24:23 瀏覽:529
vb循環腳本 發布:2025-08-23 07:18:31 瀏覽:745