Android Stroke Shape Drawable Left for TextView - android

Following is my drawable xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="1dp"
android:color="#color/button_blue" />
Following is textView xml
<TextView
android:id="#+id/tvOrigin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:drawableLeft="#drawable/circle_cab"
android:drawablePadding="16dp"
android:drawableTint="#color/deal_disc_bg"
android:ellipsize="end"
android:lineSpacingExtra="2sp"
android:maxLines="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="ksjkdjksjkdjkj"
android:textSize="14sp" />
I found that drawable is not appearing on left side of textview
Then I have added following to drawable xml
<size
android:width="10dp"
android:height="10dp" />
After adding this line I a getting drawable in left but it is drawing solid circle and not stroke
Any idea how to add stroke circle as drawable left to textview only through XML and not pragmatically.

I think that all circle it is a stroke. what I Mean that you width of stroke is exactly the size (consider left stroke 1 and right stroke 1) to fix it try to increase the size or decrease the width of the stork.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="0.5dp"
android:color="#color/button_blue" />

Related

Android-EditText Border is not visible

I am trying to create a border around a EditText but it does not work
Here is my EditText code
<EditText
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_margin="16dp"
android:autofillHints="no"
android:background="#drawable/edit_text_border"
android:hint="#string/text"
android:inputType="number"
android:padding="8dp"
android:textColorHint="#757575" />
Here is my .xml code
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:color="#color/border"/>
<corners android:radius="5dp"/>
</shape>
Edit: I tried adding solid color but the whole box became of that color and not just border.
the corners are fixed
You are missing the width on stroke tags.
This should work:
<stroke android:color="#color/border" android:width="5dp"/>

Blur shadow around edittext with rounded corners

can anyone explain and give me an example - how to add blurred shadow around edittext with rounded corners
like on a picture
I think it's an elevation. What you need to do is you need to add background with rounded corners to EditText and set margin to the EditText because without margin your shadow will be cutted off.
edittext_background.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/white"/>
<corners android:bottomRightRadius="8dp" android:bottomLeftRadius="8dp"
android:topLeftRadius="8dp" android:topRightRadius="8dp"/>
</shape>
EditText:
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:elevation="8dp"
android:background="#drawable/edittext_background"
android:layout_margin="16dp" />

android rounded corner textview with perfect round in the corner

How to show a textview with rounded corner rectangle as shown in the orginal image
in the above (original) picture, the button 2's left and right rounded corner are correctly shaped but in my code the left and right rounded corners are not shaped correctly
in the second picture I need to do more rounded as the 1st image. how can I do with following drawable?
drawable code (green_bg.xml)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#19D8C8" />
<corners android:radius="3dip" />
<stroke
android:width="10dp"
android:color="#19D8C8" />
</shape>
activity_main.xml
.......
<TextView
android:id="#+id/qmap_2"
android:layout_width="35dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="2"
android:textStyle="bold"
android:textColor="#color/no_color" />
......
create a file round.xml in drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#176d7a" />
<corners android:radius="50dp" />
</shape>
now set the background of textview like
<TextView
android:id="#+id/qmap_2"
android:layout_width="35dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="2"
android:textStyle="bold"
android:background="#drawable/round"
android:textColor="#color/no_color" />
it should work
Change the corner radius to a much higher value i.e 100dp
<corners android:radius="100dip" />

How can I show a label with text in the middle?

I am trying to get a TextView with white background and rounded corners and text in the middle.
Something that looks like this:
So far I have this but it is not giving me the above effect.
<TextView
android:textColor="#000000"
android:background="#FFFFFF"
android:text="0" />
First of all, I would create a custom drawable resource for easy implementation of rounded corners.
(place this in res/drawable)
my_bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="ffffff" />
<corners
android:radius="15dp"/>
<stroke
android:width="1dp"
android:color="#android:color/black" />
</shape>
More info on xml drawable resources can be found right here if you want to get into more advanced drawables (gradients, layer-list, animation, etc...)
Then change your TextView in xml layout file to match this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:textColor="#000000"
<!--refer to your custom drawable from earlier-->
android:background="#drawable/my_bg"
<!--center text within TextView-->
android:gravity="center"
android:text="0" />
I hope this helps, Happy Coding!
Set the gravity
android:gravity="center"
http://developer.android.com/reference/android/widget/TextView.html#attr_android:gravity
You are missing the width and height attribute for TextView.
For the rounded corners use a Shape Drawable
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
Under res/drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="#FFFFFF"/>
<corners android:radius="7dp" />
<stroke android:width="5px" />
</shape>
Then
<TextView
android:layout_width="100dp"
android:layout_height="50dp"
android:background="#drawable/background"
android:gravity="center"
android:text="0"
android:textColor="#000000" />
Snap

android:shape="line" not visible

I have the following drawable shape:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:width="1dp"
android:color="#e0e0e0" />
</shape>
And use this with this image:
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:src="#drawable/line" />
When I set android:layout_height to 1dp, the shape is not visible. If the android:layout_height is set to 2dp, the shape is visible.
Why do I have to use a height of 2dp?
Ralph
It's a stroke, so it goes around the shape. Meaning it passes the line on both sides, so it will need twice the width of the stroke.
You could just set <size> tag in your shape and put that on 1dp and <solid android:color=""> for the color

Categories

Resources