我对Android很新,我有些疑惑.
我有一个TextView:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go Back" />
为什么我要把文字Go Back看起来像可点击的?我问的是外观和感觉. TextView应该像Button一样可以显示.
提前致谢.
解决方法:
在你的drawable文件夹中创建一个名为“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添加到drawables文件夹中…… mybutton1.png,mybutton2.png.
所以你的按钮有两种不同的状态.
现在将背景设置为textview:
android:background="@drawable/mybutton"
那么,在你的代码中你必须设置一个clicklistener:
findViewById(R.id.mytextview).setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//your code goes here
}
});
这就是全部……您也可以使用形状而不是图像.