How to put a border in an EditText? [duplicate] - android

This question already has answers here:
How to have EditText with border in Android Lollipop
(6 answers)
Closed 5 years ago.
anybody could tell me, how to put a border in an editText in AndroidStudio?
for example a square in an editText.

It's so easy bro
First step create an shape.xml in your directory drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#android:color/black"/>
</shape>
Second step create your editext in your layout.xml and put background with the shape that you created above
<EditText
android:id="#+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/shape"/>
It's all

just try this one,
first create one XML file, inside drawable folder (use new drawable xml) and add this lines
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"/>
<solid android:color="#000000"/>
<stroke
android:color="#ffffff"
android:width="05dp"/>
<corners android:radius="20dp"/>
then add this line inside Your edittext property
android:background="#drawable/(file_name)"
i don't know what your expecting, maybe it will help you

Related

create custom shape with android studio? [duplicate]

This question already has answers here:
Android - drawable with rounded corners at the top only
(10 answers)
Closed 4 years ago.
I want to create this shape for my app but I can't create this shape in the editor
Create a drawable called bg_custom_textview.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/SomeColor"
/>
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
/>
</shape>
Use this as your textview background,
<TextView
android:background="#drawable/bg_custom_textview"
/>

How to make android round buttons

I have tried to search this a lot however I was not able to make the same buttons as in the picture for android.
I have been trying to use the following code but the button is not transparent and it doesn't have that nice rounding on the sides:
<?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" />
</shape>
Currently it looks like this
I want the EditTexts and the buttons to be transparent with a white border
It would be a great great help if someone could assist me on this.
Defining shape is proper approach. If you want it to be transparent with white border you need to avoid using solid tag and use stroke (that is the border).
So for example you will have this shape (let's call it bg_button.xml under drawable folder):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:color="#android:color/white" android:width="1dp" />
<corners android:radius="15dp" />
</shape>
Apply then this to your views as background. This is an example:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Facebook"
android:background="#drawable/bg_button"/>
Please try this not just on Android Studio editor but also on your emulator / device. Rendering of rounded corners on Android Studio editor can create problems.
Say you have a xml drawable called rounded_button
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#6E6E6E"/>
<corners
android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp"/>
</shape>
You then set the background of the button to the #drawable resource you created.

Strike through Multiline TextView [duplicate]

This question already has answers here:
Is there an easy way to strike through text in an app widget?
(20 answers)
Closed 7 years ago.
This in not a duplicate question, i found some question but they were not having satisfied answers, answers were not available for multiline textviews.
I have already checked this below link but they were not enough useful:
Is there an easy way to strike through text in an app widget?
I want to create a line across the center of a TextView (striked TextView), but I want to do it in XML layout, not in the Java code.
I have already achieved this result through the use of JAVA code as such:
myTextView.setPaintFlags(myTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
I would like the same result, but in the below XML code:
<TextView
android:id="#+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Thanks again.
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="XYZ"
android:background="#drawable/line"/>
line.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp"
android:color="#android:color/white"/>
</shape>
Try this !
EDIT
The above code will work only for single line text.
For Multi line text use below code :
<string name="strike_text">
<strike>sample TextView \nSecond line of TextView</strike>
</string>
And use it as
android:text="#string/strike_text"
Easiest way would be to use an image.
create image with horizontal line and transparent background and set it as background of TextView
android:background="#drawable/strike_through"
Or
Create an xml file which will draw a line and set it as background of your TextView
<shape android:shape="line">
<stroke android:width="2dp" android:color="#ffffff" />
</shape>
The way to do this in xml is to create a drawable of the strike and set it as the background of the TextView. An example of the drawable would be:
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="2dp" android:color="#ffffff" />
</shape>
</item>

How to add border to button in android [duplicate]

This question already has answers here:
Android - border for button
(11 answers)
Closed 2 years ago.
Hi I'm covering my ImageView in buttons but while they are so close to each other you cant make out that it is buttons, its just a big red square. I need a quick and easy way to give my buttons borders/edges or something so you can see the different buttons.
Create a Shape in Drawable Resource
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#C0213A" />`<!--Background Color-->`
<stroke android:width="2dip" android:color="#C0213A"/> `<!--Border-->`
</shape>
In your XML
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:background="#drawable/your_shape"> `<!--This is your shape created--`>
There is no border for buttons but you can use shape to make a drawable with border then put it as background for the button.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/red" />
<stroke
android:width="1dp"
android:color="#color/black" />
</shape>

Rounded corners of Button [duplicate]

This question already has answers here:
How to make the corners of a button round?
(19 answers)
Closed 9 years ago.
Basically, from what I have noticed is that when you add a background color to a button, the rounded corners element disappears, so basically there are no rounded corners. But when I don't have a background color, the corners of the button are round.
I don't understand whats happening.
Please Help
The border is part of the default background drawable so you have to replace it by one that contains borders also if this is what you want.
Take the default background resource and edit it to have some color.
Alternatively you can use
button = (Button) findViewById(R.id.button);
button.getBackground().setColorFilter(color, Mode.SRC_ATOP);
which perhaps gives something closer to what you expect.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_enabled="false">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp" android:shape="rectangle">
<solid android:color="#FFb888"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/>
</shape>
</item>
<item android:state_enabled="true" android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp" android:shape="rectangle">
<solid android:color="#FFD488"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/>
</shape>
</item>
<item android:state_enabled="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp" android:shape="rectangle">
<solid android:color="#FF8C00"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/>
</shape>
</item>
</selector>
<Button
android:id="#+id/btn_add_list"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_orange_button"
android:text="#string/action_new_list"
android:textColor="#color/white"
android:gravity="center"
android:textSize="18sp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:onClick="doNewList"/>
You can save the above xml file that will be the background for your button in a file called rounded_orange_button.xml in the res/drawable folder. So it would be res/drawable/rounded_orange_button.xml. This will also give your button feedback to the user when they select it, follows the dsign guidelines from developer.android.com a little more closely but it is your preference. there are a million ways to skin a cat. Then reference what you created in the drawable folder inside your_layout.xml file by the second example. The color values are optional and can also be set from another resource file in the res/values/colors.xml if need be. Use the res/values/strings.xml for any strings you want displayed inside the button. Hope this helps. Also, the amount of the curve on the buttons can be adjusted by playing with the radius values in the
The background of the button is going to give you square corners. For a nice custom background, I would suggest making a background image and using as either the button's background or src. So your xml would look like:
android:src="#drawable/mybuttonimage"
android:bacgkround="#null"
or
android:background="#drawable/mybuttonimage"
I would test out both, as they can stretch your image differently.
Another option is to to create a shape in your res/drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#33DDFF" />
<corners android:radius="4dp" />
</shape>

Categories

Resources