Reputation: 1600
I have five text view and all are clickable, how to give them a visual effect so that the user can identify it is clickable. I already dropped the idea of underlining the textview, so is there any other way available.
My code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#94FFFF" /> <!-- pressed -->
<item android:state_focused="true"
android:color="#94FFFF" /> <!-- focused -->
<item android:color="#5C9E70" /> <!-- default -->
</selector>
Upvotes: 2
Views: 1389
Reputation: 3218
My favourite is to draw a circle around the TextView and actually make it a button that contains the style elements of a TextView;
<Button
android:id="@+id/quit"
style="@android:style/Widget.TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Your Text"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:minHeight="0dp"
android:minWidth="0dp"
android:textColor="#ffffff"
android:background="@drawable/but_bg" />
where but_bg is an .xml containing
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:type="radial" android:gradientRadius="820"
android:startColor="#df242424"
android:centerColor="#df343434"
android:endColor="#da444444"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#ffffff" />
<corners
android:radius="7dp" />
<padding
android:left="8dp"
android:top="8dp"
android:right="8dp"
android:bottom="8dp" />
</shape>
</item>
</selector>
Using the radial colors in there you can also make it look more plastic. This then looks like
You can also apply an xml drawable to a layout, in case you want to keep the TextView. Then you just wrap it like this:
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/but_bg"
[...]>
<TextView
[...] />
</LinearLayout>
EDIT: I just realized that a Button
basically is a TextView
subclass with another style. I haven't tested this with TextView
tags but it should work the same way if someone wants to keep it a TextView
.
Upvotes: 3
Reputation: 2591
You can use a StateListDrawable
. Just create a xml file with selector
as a root tag and assign it as textColor
or backgroundColor
to your TextView
depending on the behavior you want.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_activated="true"
android:state_pressed="true"
android:drawable="@drawable/pressed_img" />
<item
android:state_activated="true"
android:drawable="@drawable/pressed_img" />
<item
android:drawable="@drawable/normal_img" />
</selector>
Also you have to make yout TextView
clickable by setting the android:clickable
attribute to true
.
Upvotes: 1