在你所谓的 “mybutton.xml” 绘制文件夹中创建一个XML文件,并写:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="@drawable/mybutton2"/>
<item
android:drawable="@drawable/mybutton1"/>
</selector>
然后添加两个PNG的到你的绘图资源文件夹... mybutton1.png,mybutton2巴纽。 所以你有2个不同的状态为您的按钮。
现在将背景设置为你的TextView:
android:background="@drawable/mybutton"
然后,在你的代码中必须设置一个clicklistener:
findViewById(R.id.mytextview).setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//your code goes here
}
});
而这一切......您可以使用形状,而不是图像太。
意味着点击后你想改变textview图像如果我没事吧????? – duggu 2013-02-13 11:15:57
这是重复的问题。 http://stackoverflow.com/questions/5537043/making-a-textview-clickable-in-android – Shadow 2013-02-13 11:19:57
只需使用按钮? – 2013-02-13 11:21:32