簡體   English   中英

如何使Android TextView TextColor保持突出顯示?

[英]How to make an Android TextView TextColor stay highlighted?

我在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"
      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.其他選項設置textview閃爍:

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

此功能設置為使您的文本視圖閃爍.....

希望對您有用。

Selection類可用於實現您的目標。 請參閱下面的Selection類的官方文檔:

http://developer.android.com/reference/android/text/Selection.html

另外,以下鏈接可能會很有用:

ClickableSpan TextView在單擊后保持選中狀態

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM