Child background attribute overrides the parent rounded corner of the background

I created a navigation bar using a LinearLayout containing a Clickable TextView for containing a LinearLayout. I set the XML form of the background to create rounded corners, the problem is that when the user clicks on one of the tabs that I set to the back color of the tab, the rounded corners are overwritten, the reason I set the rounded corners in the container, and not in tabs, is that the right-left / left-right languages.

Before clicking

enter image description here

After pressing

enter image description here

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="@drawable/rounded_corners"
android:layout_height="40dp"
android:layout_margin="10dp">

<TextView
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:textColor="@color/registerButton"
    android:gravity="center"
    android:text="A"/>

<View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:background="@color/registerButton">
</View>

<TextView
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:gravity="center"
    android:textColor="@color/registerButton"
    android:text="B"/>

<View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:background="@color/registerButton">
</View>

<TextView
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:textColor="@color/registerButton"
    android:gravity="center"
    android:text="C"/>

<View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:background="@color/registerButton">
</View>

<TextView
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:textColor="@color/registerButton"
    android:gravity="center"
    android:text="D"/>

@ drawable / rounded_corners

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF"/>
    <stroke android:width="1dip" android:color="@color/registerButton" />
    <corners android:radius="8dip"/>
    <padding android:color="@color/registerButton"
        android:left="0dip"
        android:top="0dip"
        android:right="0dip"
        android:bottom="0dip" />
</shape>
+4
source share
2 answers

A, :

  <corners
   android:bottomLeftRadius="5dp"
   android:topLeftRadius="5dp">
  </corners>

+1

xml , , drawables.

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#0066ff"/>  //new blue color, change the color code as you wish
<stroke android:width="1dip" android:color="@color/registerButton" />
<corners android:radius="8dip"/>
<padding android:color="@color/registerButton"
    android:left="0dip"
    android:top="0dip"
    android:right="0dip"
    android:bottom="0dip" />
</shape>

java, onclick .

0

Source: https://habr.com/ru/post/1623394/


All Articles