0

I've TextView. I need to make it clickable, white and with "selectable effect", besides I need it to have a rectangular white border, to fake a button borders:

TextView example

<TextView
    android:id="@+id/test"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?android:selectableItemBackground"
    android:background="@drawable/white_empty_rectangle"
    android:clickable="true"
    android:padding="10dp"
    android:text="Test"
    android:textColor="@color/white" />

I can't set two background properties...how can I somehow "intersect" the two properties?

EDIT: I only need the borders of the rectangle, so it is "empty", I should see the background color behind the TextView.

Jumpa
  • 3,731
  • 9
  • 41
  • 86

2 Answers2

1

Check this answer https://stackoverflow.com/a/5295522/4848308 you should use background selector. This one to achieve border line background https://stackoverflow.com/a/3496310/4848308

I hope it helps!

Community
  • 1
  • 1
Gueorgui Obregon
  • 4,688
  • 2
  • 29
  • 54
  • You perfectly right but I've to guess the system color of the pressed state of the background, I'd like to remain with ?android:selectableItemBackground if possible. Many thanks anyway. – Jumpa Jan 27 '16 at 14:55
  • 1
    You have to use the selector as suggestet. Another option would be to use an ImageButton if you don't need input to your TextView (but which you need I guess). – dipdipdip Jan 27 '16 at 14:57
  • What do you mean by "input to your TextView"? – Jumpa Jan 27 '16 at 15:01
0

What about this?

<FrameLayout
    android:id="@+id/frame_test"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?android:selectableItemBackground"
    android:clickable="true">

    <TextView
        android:id="@+id/test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/rectangle_empty_white"
        android:padding="8dp"
        android:text="@string/test"
        android:textAllCaps="true"
        android:textColor="@color/white"
        android:textSize="14sp" />
</FrameLayout>
Jumpa
  • 3,731
  • 9
  • 41
  • 86