开发者

Is there any easy or automatic way to specify text color selector for click event?

开发者 https://www.devze.com 2023-01-08 03:01 出处:网络
I specified a selector drawable for the background of a layout as below, so when user clicks on the layout, the layout will have a different background. But, I didn\'t specify color selector for the T

I specified a selector drawable for the background of a layout as below, so when user clicks on the layout, the layout will have a different background. But, I didn't specify color selector for the TextViews in the layout, because there are many TextViews with different colors and I am too lazy to define color selector for them. So the text c开发者_如何学JAVAolor keeps the same when the layout is clicked. My questions is, is there an automatic way to specify that the text color is highlighted/changed when the layout is clicked, so I don't have to define color selector for each of the TextViews in a layout? Thanks.

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/background_selector"
    >

    <TextView android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:textColor="@color/my_green"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        />
    <TextView android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:textColor="@color/my_blue"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/text1"

        />
      </RelativeLayout>


You should be able to define a theme as an XML file and set it with Activity.setTheme() - that will globally apply to everything.

0

精彩评论

暂无评论...
验证码 换一张
取 消