Issue
I face a strange issue when i use "CardView" to create a button with rounded corners. Let me explain you the design issue i face. Here is the code is use to make round corner button:
<androidx.cardview.widget.CardView
android:id="@+id/tv_email_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_error_message"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp"
app:cardBackgroundColor="#f15b5d"
app:cardCornerRadius="34dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/submit_btn_bg">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/next"
android:textSize="16sp"
android:textColor="@android:color/white"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
I use "submit_btn_bg" as backgroudn in RelativeLayout. Here is the code of file "submit_btn_bg":
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#f15b5d" />
<corners android:radius="24dp" />
</shape>
Now when i run app in android 7.0 it look like this("Next Button"):
But when i run same code in Android 10 it look fine like this:
I not this behavior is in Cardview. Anyone know how i solve this?
Solution
This is a better representation of the Button above, the output is very similar to yours and lesser code.
<com.google.android.material.button.MaterialButton
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:backgroundTint="#F44336"
android:padding="8dp"
android:text="Next"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="16sp"
android:theme="@style/Theme.MaterialComponents"
app:cornerRadius="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Answered By - Favour Felix Chinemerem
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.