I know it is a small thing but I don't know why it is not working.
when I am putting custom drawable image it is not working. I want to have a transparent background button with corners (stroke).
below is the image.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/welcome"
tools:context=".MainActivity">
<ImageView
android:id="@+id/app_logo"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:src="@drawable/applogo"/>
<TextView
android:id="@+id/app_slogan"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="80dp"
android:layout_marginTop="140dp"
android:text="Find, Discover, Choose and buy anything online"
android:textAlignment="center"
android:textSize="22sp"
android:textStyle="bold|italic"
android:textColor="@color/design_default_color_primary"
/>
<Button
android:id="@+id/main_login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="10dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:background="@drawable/buttons"
android:padding="20dp"
android:textAllCaps="false"
android:textSize="18sp"
android:text="Already have a account ? Login"
android:textColor="@android:color/white"
/>
<Button
android:id="@+id/main_join_now_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_above="@id/main_login_btn"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:background="@drawable/input_design"
android:padding="20dp"
android:textAllCaps="false"
android:textSize="18sp"
android:text="Already have a account ? Login"
android:textColor="@android:color/white"
/>
</RelativeLayout>
// Drawable resource file.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:color="#fff"
android:width="3dp"
/>
<corners
android:radius="15dp"
/>
login button should have a background of input_design.xml but I don't know why it is not working. help me out thank you in advance.
To achieve a transparent background on your button perhaps use Widget.MaterialComponents.Button.OutlinedButton.
You will need this line in your build.gradle (if not there already):
implementation 'com.google.android.material:material:1.2.1'
Your button would then simply look like this:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/teal_700"
tools:context=".FirstFragment">
<Button
android:id="@+id/button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:text="I am a Button!"
android:textColor="@color/white"
app:cornerRadius="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:rippleColor="@color/white"
app:strokeColor="@color/white"
app:strokeWidth="3dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Notice:
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:textColor="@color/white"
app:cornerRadius="15dp"
app:rippleColor="@color/white"
app:strokeColor="@color/white"
app:strokeWidth="3dp"
and that will produce:
Please see my updated answer using material outlined button components instead. This would be the preferred solution to achieve what you are looking for without the use of any extra xml shapes etc.
Thanx, this works for me .. but tell me one this after the latest update of android studio delicate dark mode (theme) and light mode theme is available, to implement but why don't drawable resource file when I am creating it and using as a background why it is not working.. help me
Are you asking why the question I just answered doesnt work the way you want it to? If so Im not sure, but it seems like the xml isnt corretcly being applied and your theme is taking over, either way this is the new way of doing it and probably the better way, no use in keeping up with the old stuff in my opinion. If you want to do this across the board you would create a style in your theme and apply that to all buttons of that style.
It worked for me ... Earlier I used create drawable resource and put it as a background but now after new update of AS it is not working ... But your method worked for me thank you for that
Yeah I don't know why it stopped working probably had to do with the themeing and new components but usually mixing older ways of doing things with the newer stuff like Android material will cause things to not work as expected. Also the old way was crap in my opinion. You can do what you want much quicker without any extra xmls that end up bloating the project and lying around. Just an FYI I tried your old method and couldn't get it to work hence I went with another approach I used in one of my projects.