sp; editText = (EditText) findViewById(R.id.edit);
text = (TextView) findViewById(R.id.text);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text.setText(editText.getText());;
}
});
}
text.setOnClickListener()方法是text监听方法.用来监听TextView的点击事件。
整个流程就是在输入文本后点击text然后text的文本就会被替换成你输入的文本.
Button 与 ImageButton
本节学习Android基本控件按钮控件,Button和ImageButton用法基本类似,所以本节重点讲解Button控件。
1)代码:
<Button
android:id="@+id/btn"
android:text="普通按钮"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
2)Button的其他常用属性:
-background 背景 可以是颜色或者图片或这xml资源
-text 按钮显示的文字
-textColor 按钮文字颜色
-textSize 按钮文字大小
3)Button控件的绑定和监听:
绑定
btn = (Button) findViewById(R.id.btn);
监听的方法很常用
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this , "button 被按下" , Toast.LENGTH_LONG).show();
}
});
4)Toast方法是常