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.
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
To
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.
drawable
directory are perfectly working, no red text error, autocomplete working for every resource in the drawable directory.Empty StateList
for shape
is wrapped in selector
shape
that is applied to the button's background
Everything in style other than the things that use resources from drawable works perfectly. (textSize, padding and etc.)
There is only one drawable
directory in this project, there isn't any drawable-xx
.
android.app.Activity
, android.app.Fragment
, android.widget.ImageView
had been used.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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With