① android开发中点击button无反应大神来看看这个代码的问题在哪里
把 button_listener = new Button.OnClickListener() {
public void onClick(View v) {
//setTitle("哎呦,button被点了一下");
Intent intent=new Intent(MainActivity.this,edText.class);
startActivity(intent);
} 这段放到 onCreate 方法外面
Button.OnClickListener button_listener = new Button.OnClickListener() {
public void onClick(View v) {
//setTitle("哎呦,button被点了一下");
Intent intent=new Intent(MainActivity.this,edText.class);
startActivity(intent);
}
② android开发 如何随机选button
10个button的引用放到MAP<int,Button>中,key为1-10,value为10个button的引用,
然后取1-10随机数,再通过取到的随机数去map中取button
OK了
③ 如何在android当中实现Button操作
你可以现在布局文件layout中添加button控件,然后对其属性设置,最后在src文件中,编写java文件,对该按钮的功能进行设置,并监听按钮事件
④ Android开发中,如何给动态生成的Button指定Style样式
自定义样式方法,可以直接通过定义xml文件来实现不同的样式:
只需要修改button_style文件,同样三种状态分开定义:
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient android:startColor="#0d76e1" android:endColor="#0d76e1"
android:angle="270" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="2dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient android:startColor="#ffc2b7" android:endColor="#ffc2b7"
android:angle="270" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="2dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient android:startColor="#000000" android:endColor="#ffffff"
android:angle="180" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="5dip" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>
</selector>
gradient 主体渐变 startColor开始颜色,endColor结束颜色 ,angle开始渐变的角度(值只能为90的倍数,0时为左到右渐变,90时为下到上渐变,依次逆时针类推)
stroke 边框 width 边框宽度,color 边框颜色
corners 圆角 radius 半径,0为直角
padding text值的相对位置
⑤ android中button有几种状态
Android中,button按钮通常有三个状态:
1. normal(正常状态);
2. focus(焦点状态);
3. pressed(按下状态)
4. selected(选中状态)
注意:按下后未松开前是pressed,表示按下。
松开后当前项目获得焦点,是focused。
focused的项只有一个,selected是当选中该按钮时显示的状态。
⑥ Android 开发里面如何点击Button将EditText里面的内容显示在textView里
1、添加button的单击事件
2、获取edittext的内容
3、往textview中赋值
示例:
Button btn = (Button)findViewById(R.id.xxx);//获取按钮
btn.setOnClickListener(new View.OnClickListener() {
//设置按钮单击事件
@Override
public void onClick(View v) {
EditText et = (EditText)findViewById(R.id.xxxx);//获取edittext组件
TextView tv = (TextView)findViewById(R.id.xxxx);//获取textview组件
String cn = et.getText().toString();//获取edittext中填写的内容
tv.setText(cn);//在textview中显示
}
});
⑦ android开发中,button的text(settext方法)可以动态的设置吗
可以。
1、通过id获取button组件
Buttonbtn=(Button)findViewById(R.id.xxxx);//获取button组件对象
2、通过setText方法改变button的text属性
btn.setText("改变后的值");//改变button的文本显示