0

Recently i updated my android studio and i am facing lots of problems such as its not showing the particular error. In previous version if did any thing wrong in coding it shows red line under the code and now i am facing new problem I created a background design layout for buttons after i applying this background layout in my buttons it's not changing my button background i don't know what happened with my project or maybe software.

Here is my Button design layout which name is btn_design

<?xml version="1.0" encoding="utf-8"?>
<shape
    android:shape="rectangle"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="@dimen/_10sdp"/>
    <solid android:color="#00AD01"/>

</shape>

Here is my main Activity layout where i applied this design code.

<?xml version="1.0" encoding="utf-8"?>
<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="#ED000000"
    android:orientation="vertical"
    tools:context=".activites.IntenetChecker">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:layout_width="@dimen/_130sdp"
            android:layout_height="@dimen/_130sdp"
            android:src="@drawable/ic_wifi_off_24"
            android:layout_marginTop="@dimen/_50sdp"
            android:layout_gravity="center_horizontal"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_20sdp"
            android:gravity="center"
            android:fontFamily="monospace"
            android:padding="@dimen/_5sdp"
            android:textColor="@color/white"
            android:textSize="@dimen/_18ssp"
            android:textStyle="bold"
            android:text="You are offline"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_20sdp"
            android:gravity="center"
            android:fontFamily="monospace"
            android:padding="@dimen/_5sdp"
            android:textColor="#A8ffffff"
            android:textSize="@dimen/_18ssp"
            android:textStyle="bold"
            android:text="Check your internet connection and try again"/>


        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_design"
            android:padding="16dp"
            android:paddingLeft="100dp"
            android:drawablePadding="-100dp"
            android:gravity="center"
            android:text="Try again"
            android:layout_margin="@dimen/_35sdp"
            android:drawableLeft="@drawable/ic_refresh_24"/>
    </LinearLayout>
</RelativeLayout>

Here is my output of that layout in xml design page

enter image description here

Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • 3
    Does this answer your question? [Android Button background color not changing](https://stackoverflow.com/questions/31858374/android-button-background-color-not-changing) – MJV Jan 08 '21 at 01:55

1 Answers1

3

Either a new bug or feature causes this issue. You have to change Button to AppCompatButton, as said in this answer.

The color of the button is set to the colorPrimary value in the default themes.xml file. Even if you have a background set, the button's color will still be set to the primary color in the themes file, but the shape of the button will be set to the design of the btn_design file.

Previously, whenever you made a project in Android Studio, the project's theme would be declared in the styles.xml file. After a recent update, this changed and the project's theme is declared in the themes.xml file, which is located in the themes folder. While they both have the same functionality, a modification created this issue.

Whether it is a bug or a feature is out of my reach.

MJV
  • 652
  • 5
  • 14