How to add border to button in android [duplicate] - android

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>

Related

Rounding the corners of a View in Kotlin [duplicate]

This question already has answers here:
How do I create a ListView with rounded corners in Android?
(11 answers)
Closed 2 years ago.
I have this View in Kotlin:
<View
android:id="#+id/DotView"
android:layout_width="6.5dp"
android:layout_height="6.5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/colorPrimary"
/>
and I need to round the corners since it is a Dot and I have been investigating and testing how I can do it to round the corners but I just can't find the answer.
How can I solve it?
you have to create a drawable shape xml file and set background property of the view to the drawable file!
res/drawable/circle.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#color/colorPrimary" />
</shape>
res/drawable/rounded.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/colorPrimary"/>
<corners android:radius="5dp" />
</shape>
and set background to view like this :
<View
android:id="#+id/DotView"
android:layout_width="6.5dp"
android:layout_height="6.5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#drawable/rounded"
/>

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 put a border in an EditText? [duplicate]

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

Two background color in a frameLayout Android [duplicate]

This question already has answers here:
banded background with two colors?
(5 answers)
Closed 8 years ago.
In android xml we set the background as following
android:background="#FF88FF"
Now In frameLayout how can I use tow background color. E.g. top 50% should be red bottom 50% should be black
<FrameLayout
android:layout_width="match_parent"
android:layout_height="37dp"
android:layout_weight="0.79"
android:background="#FF88FF"
android:padding="25dp" >
</FrameLayout>
How to do this???
You should do the custom drawable, which will include 2 shapes - 2 rectangles. Something like this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="50dp">
<shape android:shape="rectangle"
android:dither="true">
<solid android:color="color1"/>
</shape>
</item>
<item android:bottom="50dp">
<shape android:shape="rectangle"
android:dither="true">
<solid android:color="color2"/>
</shape>
</item>
</layer-list>
Please note, that absolute values are used here for sizes. For relative sizes I think you should create custom Drawable programmatically by extending Drawable class.

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