XML : Add Rounded corners to StateSelected Background of TextView using XML

I have RecyclerView which holds some TextViews. I have set background of the RecyclerView to the following recycler_view_background.xml.

  <?xml version="1.0" encoding="utf-8"?>  <shape xmlns:android="http://schemas.android.com/apk/res/android">      <solid android:color="#000000" />      <corners android:topLeftRadius="@dimen/player_category_radius" android:topRightRadius="@dimen/player_category_radius"          android:bottomLeftRadius="@dimen/player_category_radius" android:bottomRightRadius="@dimen/player_category_radius"/>      <stroke android:color="#D3D3D3" android:width="1dp" />  </shape>    

And it works fine, I get rounded corners on my RecyclerView.

Here's the catch, when I try to add a background selector to any one of the TextViews they don't show rounded corners. Here's the background xml for each item category_item_selector.xml.

  <?xml version="1.0" encoding="utf-8"?>  <selector xmlns:android="http://schemas.android.com/apk/res/android">      <item android:state_selected="true" android:drawable="@drawable/controlbar_gradient">          <shape>              <corners android:topLeftRadius="@dimen/player_category_radius" android:topRightRadius="@dimen/player_category_radius"                  android:bottomLeftRadius="@dimen/player_category_radius" android:bottomRightRadius="@dimen/player_category_radius"/>              <stroke android:color="#D3D3D3" android:width="1dp" />          </shape>      </item>  </selector>    

I am programmatically setting TextView's selected to true in my RecyclerView.Adapter.ViewHolder's OnClickListener (Selector is working fine or else I wouldn't have reddish background to the selected item).

Here are the snippets from the application. enter image description here

RecyclerView has rounded corners but TextView's background is drawing over it. So when the selected View is on Top or Bottom.

enter image description here

Rounded corners are no longer visible even though it shouldn't when I have added rounded corners on selected views.

I keep getting similar solutions when searching for this. And mine is correct according to this.

No comments:

Post a Comment