如何使Android TextView TextColor保持高亮显示?
我在ListView中有一个TextView。我希望TextView的TextColor在选中时保持高亮显示。它在较新版本中工作正常,但在较低版本中没有高亮显示,只是闪烁 以下是我的xml: listview_bell_items.xml如何使Android TextView TextColor保持高亮显示?,android,Android,我在ListView中有一个TextView。我希望TextView的TextColor在选中时保持高亮显示。它在较新版本中工作正常,但在较低版本中没有高亮显示,只是闪烁 以下是我的xml: listview_bell_items.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<TextView
android:id="@+id/txt_bell_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/rihanna_love_the_way_lie"
android:textColor="@drawable/bell_selected_text_color"
android:textSize="15sp"
android:textStyle="bold"
android:typeface="sans" />
<ImageView
android:id="@+id/list_bell_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/bronze_bell" />
</RelativeLayout>
bell_selected_text_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/light_yellow"/>
<item android:state_focused="true" android:color="@color/light_yellow"/>
<item android:state_checked="true" android:color="@color/light_yellow"/>
<item android:state_selected="true" android:color="@color/light_yellow"/>
<item android:color="@color/white"/>
</selector>
1.您可以使用setAlpha(0到255值)在textview中进行设置,以便在android textview中高亮显示或设置不透明度
Use this link: http://stackoverflow.com/questions/2838757/how-to-set-opacity-alpha-for-view-in-android
(对于在textview中设置的不透明度)
2.其他选项设置文本视图闪烁:
public static void blinkView(final TextView txtView) {
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(400); // You can manage the time of the blink with this
// parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
txtView.startAnimation(anim);
}
此功能设置为闪烁您的文本视图
我希望它对你有用。选择课程可以用来实现你的目标。请参阅以下选择类的官方文档: 此外,下面的链接也很有用:
我不想让TextView闪烁。我希望TextView保持高亮显示。请使用第一个选项。它对您很有用@Kousikt链接没有打开@Dipali是否应该将选择器放置在res/color中?选择器是否应该放置在res/drawable@pskink中…选择器是否应该放置在res/color中?您的意思是您应该将选择器放置在res/color而不是res/drawable中?不,它不起作用..我不希望选择TextView。单击TextView后,我希望颜色将会改变。