Please check this link also. What should i use for better performance, nine-patch or drawable xml resource?. Both approaches have is own merits. Select one option as per your situation
Button with Nine-patch or Style?
-
30-09-2022 - |
سؤال
I'm making an app with custom buttons, but I want to know is it better to use the nine-patch tool or define styles and colors in xml. My buttons change in height and width but they do not have images, just words, something like this:
المحلول
نصائح أخرى
no you don't need to use nine-patch just give the width,height,and text sizes in values folder.
Seems like a fairly simple shape, you might as well use a shape to create the background.
first create a button_shape.xml
file in drawable resource directory:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#505050"/>
<corners
android:radius="7dp" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp"
android:bottom="1dp"/>
<solid android:color="#505050"/>
</shape>
Now, assign it to the backround of you Button
.
android:background="@drawable/button_shape"
You will need to change some of the color values to fit your needs
لا تنتمي إلى StackOverflow