Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resources in drawable directory not work properly

Tags:

android

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.

  • References to those resources in drawable directory are perfectly working, no red text error, autocomplete working for every resource in the drawable directory.
  • However, when I hold cursor above those resources name, it said Empty StateList for shape is wrapped in selectorenter image description here
    for other resources that aren't wrapped in selector, it just shows the full path to a resource file in red text. Everything work with style except shape that is applied to the button's backgroundenter image description here
  • Everything in style other than the things that use resources from drawable works perfectly. (textSize, padding and etc.)

    Additional information

  • There is only one drawable directory in this project, there isn't any drawable-xx.

  • Before I migrated the application still have android support library but I think it hadn't been used. android.app.Activity, android.app.Fragment, android.widget.ImageView had been used.
like image 977
witoong623 Avatar asked Nov 07 '22 21:11

witoong623


1 Answers

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"
like image 100
DeePanShu Avatar answered Nov 15 '22 10:11

DeePanShu