witoong623
witoong623

Reputation: 1199

Resources in drawable directory not work properly

Context

This problem happened after I migrated an android application from App to AppCompact using refactor option in Android Studio 3.3 (It had been using nonsupport library version before), this process including manually changed deprecated APIs and so on.

I also updated compileSdkVersion from 27 to 28 and support library version from 27.1.1 to 28.0.0.

Everything work totally fine before I migrated and update compileSdkVersion and support library version.

Problem

After I migrated, I'm able to run in on my phone. However, I noticed that the Buttons that have been styled don't look like the way they should be.

From What it should be

To What it is right now

This is one of the styles that I applied to button.

styles.xml

<style name="GraderButton" parent="@android:style/Widget.Button">
    <item name="android:textColor">@color/text</item>
    <item name="background">@drawable/button_background</item>
    <item name="android:padding">13dip</item>
    <item name="fontPath">fonts/THSarabunNew Bold.ttf</item>
    <item name="android:textSize">20sp</item>
</style>

And this is one of the button that the above style was applied to.

<Button
    android:id="@+id/buttonScan"
    style="@style/GraderButton"
    android:layout_width="186dp"
    android:layout_height="53dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_weight="1"
    android:text="@string/action_scan"
    app:layout_constraintBottom_toTopOf="@+id/progressStatus"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="@+id/guidelineMiddle"
    app:layout_constraintVertical_bias="0.39999998" />

Apparently, from some test I did, shape resources that are applied to background is not recognized or not work properly. From that I investigated.

Upvotes: 5

Views: 919

Answers (1)

DeePanShu
DeePanShu

Reputation: 1326

Actually here in GraderButton style there is

item name="background"

which is not attribute of Button (Widget) So, here we have to set background of button using:-

item name="android:background"

Upvotes: 1

Related Questions