简体   繁体   中英

TextView Selectable and drawable background

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示例

<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.

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!

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM