当前位置:首页 » 安卓系统 » 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背景图片。

热点内容
UE4源码编译要多久 发布:2025-02-08 07:52:50 浏览:230
java架构师做什么 发布:2025-02-08 07:38:32 浏览:774
java解码器 发布:2025-02-08 07:25:35 浏览:297
p4忘记密码了如何刷机 发布:2025-02-08 07:25:25 浏览:307
java分隔 发布:2025-02-08 07:15:02 浏览:813
源码乘法竖式 发布:2025-02-08 07:05:48 浏览:137
天天酷跑脚本脚本精灵 发布:2025-02-08 07:05:15 浏览:346
ios数据库迁移 发布:2025-02-08 07:00:16 浏览:852
安卓sdl是什么 发布:2025-02-08 07:00:05 浏览:909
脱机脚本怎么写 发布:2025-02-08 06:59:22 浏览:833