Android L is not able to draw dotted line as drawable background as below:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="line" >
<stroke
android:dashGap="1dp"
android:dashWidth="1dp"
android:color="#999999" />
<size android:height="1dp" />
</shape>
</item>
</selector>
I am also using layerType='software' in xml. Kindly help.
This example demonstrates how do I make a dotted/dashed line in Android. Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 - Add the following code to res/layout/activity_main. xml.
Go to res > drawable > new > drawable resource file and create a new file and name it “dashed_underline. xml” and define all properties of the dashed line that we need.
R. drawable. image means the drawable resource, in this case image. Drawable means graphic which can be drawn. Every drawable is stored in res/drawable folder.
Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.
1.The view must be at least 2dp in height (or wrap_content
), in order for it to display since a stroke is designed to go around the view and it doesn't have room to do so in 1dp.
2.Add width to your xml:
<stroke
android:width="1dp"
android:dashGap="1dp"
android:dashWidth="1dp"
android:color="#999999" />
<size android:height="1dp"
android:width="1dp"/>
3.Use layerType='software'
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