Android TextView disabling color-changing

放肆的年华 提交于 2020-01-04 06:22:09

问题


I have a TextView with the following XML (it's the only thing in the view):

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/ipg_display"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:text="textview"
  android:scrollbars = "vertical"
  android:fillViewport = "true" android:clickable="false"/>

The problem I'm having is that when the text view is clicked by the user (to drag through it or whatever), the text changes color slightly as if the view is being "clicked". How do I disable this?

I was hoping that settings "clickable" to false would solve the issue, but no luck :(

What am I missing?


回答1:


use the following selector for your button as the background. and make sure every item has the same color.

<?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
  <item 
    android:state_focused="true"
    android:drawable="@color/yourbackgroundcolor"/>
   <item 
    android:state_pressed="true"
    android:drawable="@color/yourbackgroundcolor"/>
  <item android:drawable="@color/yourbackgroundcolor"/>
</selector>

HTH.



来源:https://stackoverflow.com/questions/7424946/android-textview-disabling-color-changing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!