文本视图不可见性

发布于 2024-11-29 00:47:01 字数 266 浏览 5 评论 0原文

我有一个 textView,其中我在 xml 中将颜色设置为透明

android:background="#ffffff" 

现在我已经编写了代码来更改 textView onClick 的图像

t1.setBackgroundResource(R.drawable.fslash); 

,但它似乎没有对 textView 的 onClick 执行任何操作。

请帮忙

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.setBackgroundResource(R.drawable.fslash); 

but it does not seem to do anything onClick of the textView.

Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

女皇必胜 2024-12-06 00:47:01

你必须像这样实现 click 方法

 textview.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            try {
                                // Your Code
                            } catch (Exception e) {
                            }

                        }
                    });

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) {
                            }

                        }
                    });
微凉徒眸意 2024-12-06 00:47:01

试试这个,

t1.setOnClickListener(new OnClickListener(){

private void onClick(View v){

TextView txt=(TextView)v.findViewById(R.id.txtid);
txt.setBackgroundResource(R.drawable.fslash); 
}

});

try this,

t1.setOnClickListener(new OnClickListener(){

private void onClick(View v){

TextView txt=(TextView)v.findViewById(R.id.txtid);
txt.setBackgroundResource(R.drawable.fslash); 
}

});
愁杀 2024-12-06 00:47:01

尝试设置:

android:clickable="true"

您也可以在 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>

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>
猫瑾少女 2024-12-06 00:47:01

如果你想点击TextView,你必须将clickable属性设置为true。否则它不会听任何点击!您可以在代码或 xml 文件中执行此操作:

代码:

t1.setClickable(true);

XML:

android:clickable="true"

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文