TextView Invisibility
I have a textView in which i have set the color as transparent in xml
android:background="#ffffff"
Now i have written the code to change the image of the textView onClick
t1.setBackgroundRe开发者_运维技巧source(R.drawable.fslash);
but it does not seem to do anything onClick of the textView.
Please help
You have to implement click method like this
textview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
// Your Code
} catch (Exception e) {
}
}
});
try this,
t1.setOnClickListener(new OnClickListener(){
private void onClick(View v){
TextView txt=(TextView)v.findViewById(R.id.txtid);
txt.setBackgroundResource(R.drawable.fslash);
}
});
try setting:
android:clickable="true"
or
you can also do in XML:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<android:background="@drawable/yourimg" />
</item>
<item android:background="#000000" /> <!-- default -->
</selector>
If you want to click on the TextView, you have to set the clickable attribute to true. Otherwise it will not listen to any click! You can do that in code or in the xml file:
Code:
t1.setClickable(true);
XML:
android:clickable="true"
精彩评论