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"/>
Related
I want to change the color of scrollbar.
I tried to set in xml like this,
android:scrollbarThumbVertical="#color/blue"
or like this
app:fastScrollVerticalThumbDrawable="#drawable/scroll"
but it's not working.
please let me know if there is a way to change the color , thanks.
To explain more clearly
my code
<androidx.wear.widget.WearableRecyclerView
android:id="#+id/barcodeRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fadeScrollbars="false"
android:orientation="vertical"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:scrollbarStyle="insideInset"
android:scrollbarThumbVertical="#drawable/scrollview_thumb"
android:scrollbarTrackVertical="#drawable/vertical_scrollview_track"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
In my emulator, the code upon only change the original scrollBar. If I scroll page, the original scrollBar(which been changed) would disappear and the curved scrollBar would pop up.
original scrollBar(I changed it into blue)
curved scrollBar
1. Add following tags in your scrollview
android:fadeScrollbars="false"
android:scrollbarStyle="insideInset"
android:scrollbarThumbVertical="#drawable/scrollview_thumb"
android:scrollbarTrackVertical="#drawable/vertical_scrollview_track"
2. Create following drawable in your drawable folder
scrollview_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/common_google_signin_btn_text_light_focused" />
<corners android:radius="15dp" />
</shape>
3.vertical_scrollview_traack.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#E2E0EB" />
<stroke
android:width="1dp"
android:color="#b3a9a9" />
<size android:width="15dp" />
<corners android:radius="15dp" />
</shape>
how to make a edittext field in complete circle shape, not just rounded.
and force it to accept only 1 number.
i am looking for something like this
\n\n
Try this in your XML layout:
<EditText
android:id="#+id/circle_edittext"
android:layout_width="60dp"
android:layout_height="60dp"
android:gravity="center"
android:maxLength="1"
android:maxLines="1"
android:inputType="number"
android:background="#drawable/circle"
android:padding="20dp"
/>
And add a circle drawable for the background:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dip"/>
<solid android:color="#FFFFFF"/> <!-- CIRCLE COLOR -->
</shape>
Hope it helps.
I'd like to create the following custom EditText. How to make the vertical bar like the one on the picture?
Style edittext_custom_style.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#75d0e2" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
xml:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittext_custom_style"/>
Create same bar drawable and assign drawableLeft to edittext
Code put image in respective drawables like drawable-xhdpi etc
Sample is here.
<EditText
android:id="#+id/password"
style="#style/inputFieldStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/password_icon"
android:hint="#string/password_hint"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="1"/>
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
I am trying to get a rounded EditText.
My EditText in layout is like
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<EditText
android:id="#+id/EditTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_round"
android:padding="5dip"
android:singleLine="true" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/searchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="#android:drawable/ic_menu_search" />
</FrameLayout>
and the drawable I am using as EditText background is like
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners
android:bottomLeftRadius="12dp"
android:bottomRightRadius="12dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
</shape>
In my XML graphical layout, my edittext looks fine and rounded, but in emulator and also in device it does not look like that?
Does anyone have any idea why could that be?
Thanks
Remove the android:padding="10dp" attribute to make the drawable look like this. I just tested it and removing the padding attribute shows the rounded corners just fine.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<corners
android:bottomLeftRadius="12dp"
android:bottomRightRadius="12dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
</shape>
To add padding to the Shape Drawable, notice the padding attribute added in the code above.
The proof lies in the pudding: ;-)
Device Screenshot:
Emulator Screenshot:
You didn't provide the stroke element, so you probably just don't see the background (since it's only a white fill!). When you change the background or add a stroke, it should be visible.
Add:
<stroke android:width="2dp" android:color="#000000" />
And poof! The rectangle is visible :) BTW The padding isn't the issue - it's simply ignored.