I want to remove the underlining decoration when I am inputting text into my edit text. And something more, is it possible to get rid of this padding or margin that is between the inputted text and the blue border below it?
Right now the edittext looks like this:
Create a edit_text_background.xml in your drawables folder with following code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/white"></solid>
</shape>
Then simply set android:background="#drawable/edit_text_background" field to the same drawable file.
editText.setBackroundDrawable(null);
Related
I'm working on a project in android studio and I'm trying to change the border to my button.
My default button when I just add it to my grid look like this:
After adding new XML file (called box_solid_border.XML) in the drawable file that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="4dp"
android:color="#000000" />
</shape>
the result is that it's creating the next shape that I can see:
and that exactly what I want to add to my button.
when I come back to my XML at the main file and add to my button the next line:
as you can see in line 226 I'm adding the background that I just created for this button to the button. and near the line, there is the exact border that I want.
but in the application, the button still stays the same as the default one with no border added to him.
Like this:
Does someone know the reason that the drawable file doesn't affect the button?
If I'm doing the same thing for a textView or something else its works perfectly fine, just the button looks like not affected by the drawable extension to him.
Thank you!
You need to add this attribute to your button:
app:backgroundTint="#null"
If it has both attributes android:background and app:backgroundTint(if you are using the default theme for your application, it has a default value), the color specified by app:backgroundTint will be cover on the shape of drawable.
For border to button try to edit box_solid_border.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:color="#color/black"
android:width="5dp"/>
<corners
android:radius="8dp"/>
<solid
android:color="#color/colorAccent"/>
</shape>
In layout xml file
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/box_solid_border"
android:text="Button"
android:textColor="#fff"
android:textSize="30sp" />
is there any way to create a circle or a square around the number in android with special characters like this: ➊, but with own number?
Yes. use android view badger.
https://github.com/jgilfelt/android-viewbadger
of course you have second way to make it.
1. create your own xml shape file for oval shape.
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="120dp"
android:height="120dp"/>
</shape>
use a textview and set this drawable to background of textview
set every number that you want to as text to textview
for special character you can use UniCodes or some custom fonts.
<TextView
width...
height...
android:background="#drawable/createShapeInDrawableFolder"/>
As answered by Mohammad moradyar
I want to customize the EditText slider style. See my screenshots below.
This is the default slider style:
This is what I want to see:
This may be a dumb question, but after a few hours Googling, I can only find ways to change the cursor color, but couldn't find an approach to change the slider style.
This is the code I am using for changing the cursor color (color_cursor.xml):
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:width="2dp" />
<solid android:color="#008000" />
</shape>
And I applied the "android:textCursorDrawable="#drawable/color_cursor" to EditText.
Thanks.
android:textSelectHandle="#drawable/your_desired_drawable"
put this in your editText view. Set the drawable you prefer. Then change the color inside your drawable xml file.
An answer for myself (hope this will also help others):
After introducing the "Theme.material", the EditText will become the expected style. I will want to check out Material Design.
After the call of EditText.setBackgroundColor(Color.RED) I see only a red rectangle with text inside it, but I want to change only the text background and to keep the standard bottom border which is grey when the field has no focus and blue if it has focus. Can I do it programmatically?
I want to change the text background to red if the input is invalid and to transparent if it is valid.
I think the best way is to work with drawable/shape.xml as background and upon logic code situation call EditText.setBackground(some_other_shape.xml). Here is an example for shape file xml demonstrating how to use:
Border color ("stroke"): In this example some custom color from colors.xml
Fill color ("solid"): In this example Android default transparent color
Even image icon inside
<!--Example for custom shape file xml design-->
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#mipmap/icon_image" />
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke android:width="1dp" android:color="#color/orange_primary" />
</shape>
</item>
</layer-list>
So just prepare several shapes for each situation you need. Another approach is to work with layout params etc. but I think this one is faster and gives more control for custom design in easy to understand code.
I have a button that I want to be round, so I made an xml file and set it as its background. The button is now round but I want to be able to change its color programmatically instead of hardcoding it into the xml file. How can I do this?
Here is my xml file for round button.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ffcb05"/>
</shape>
You can change color of view by using ColorFilter. It is very easy and quick.
button.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
This code will color button into red color.
Try to get button background set color using getPaint :
((ShapeDrawable)yourbutton.getBackground()).getPaint().setColor(getResources().getColor(R.color.colorToSet));
Try this:
GradientDrawable backgroundShape = (GradientDrawable)btn.getBackground();
backgroundShape.setColor(Color.BLACK);