I want to make this kind of button [same background & text] colors by using XML Styles
that's just for an example, i want to write some other texts, like: About Me
Still i am using button created by designer in Photoshop
<ImageButton
android:id="#+id/imageButton5"
android:contentDescription="AboutUs"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:layout_height="wrap_content"
android:layout_below="#+id/view_pager"
android:layout_centerHorizontal="true"
android:background="#drawable/aboutus" />
Note: I need this kind of button in every size and shape
I don't want to use any image in my Android App i want to make it using XML only
Copy-pasted from a recipe written by "Adrián Santalla" on androidcookbook.com:
https://www.androidcookbook.com/Recipe.seam?recipeId=3307
1. Create an XML file that represents the button states
Create an xml into drawable called 'button.xml' to name the button states:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="#drawable/button_disabled" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="#drawable/button_pressed" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="#drawable/button_focused" />
<item
android:state_enabled="true"
android:drawable="#drawable/button_enabled" />
</selector>
2. Create an XML file that represents each button state
Create one xml file for each of the four button states. All of them should be under drawables folder. Let's follow the names set in the button.xml file.
button_enabled.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#00CCFF"
android:centerColor="#0000CC"
android:endColor="#00CCFF"
android:angle="90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<stroke
android:width="2dip"
android:color="#FFFFFF" />
<corners android:radius= "8dp" />
</shape>
button_focused.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#F7D358"
android:centerColor="#DF7401"
android:endColor="#F7D358"
android:angle="90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<stroke
android:width="2dip"
android:color="#FFFFFF" />
<corners android:radius= "8dp" />
</shape>
button_pressed.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#0000CC"
android:centerColor="#00CCFF"
android:endColor="#0000CC"
android:angle="90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<stroke
android:width="2dip"
android:color="#FFFFFF" />
<corners android:radius= "8dp" />
</shape>
button_disabled.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#F2F2F2"
android:centerColor="#A4A4A4"
android:endColor="#F2F2F2"
android:angle="90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<stroke
android:width="2dip"
android:color="#FFFFFF" />
<corners android:radius= "8dp" />
</shape>
3. Create an XML file that represents the button style
Once you have created the files mentioned above, it's time to create your application button style. Now, you need to create a new XML file, called styles.xml (if you don't have it yet) where you can include more custom styles, into de values directory.
This file will contain the new button style of your application. You need to set your new button style features in it. Note that one of those features, the background of your new style, should be set with a reference to the button (button.xml) drawable that was created in the first step. To refer to the new button style we use the name attribute.
The example below show the content of the styles.xml file:
<resources>
<style name="button" parent="#android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFFFF</item>
<item name="android:shadowColor">#FF000000</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">-1</item>
<item name="android:shadowRadius">0.2</item>
<item name="android:textSize">16dip</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/button</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
</resources>
4. Create an XML with your own custom application theme
Finally, you need to override the default Android button style. For that, you need to create a new XML file, called themes.xml (if you don't have it yet), into the values directory and override the default Android button style.
The example below show the content of the themes.xml:
<resources>
<style name="YourApplicationTheme" parent="android:style/Theme.NoTitleBar">
<item name="android:buttonStyle">#style/button</item>
</style>
</resources>
Hope you guys can have the same luck as I had with this, when I was looking for custom buttons. Enjoy.
Have you ever tried to create the background shape for any buttons?
Check this out below:
Below is the separated image from your image of a button.
Now, put that in your ImageButton for android:src "source" like so:
android:src="#drawable/twitter"
Now, just create shape of the ImageButton to have a black shader background.
android:background="#drawable/button_shape"
and the button_shape is the xml file in drawable resource:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#505050"/>
<corners
android:radius="7dp" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp"
android:bottom="1dp"/>
<solid android:color="#505050"/>
</shape>
Just try to implement it with this. You might need to change the color value as per your requirement.
Let me know if it doesn't work.
Have a look at Styled Button it will surely help you.
There are lots examples please search on INTERNET.
eg:style
<style name="Widget.Button" parent="android:Widget">
<item name="android:background">#drawable/red_dot</item>
</style>
you can use your selector instead of red_dot
red_dot:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#f00"/>
<size android:width="55dip"
android:height="55dip"/>
</shape>
Button:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="49dp"
style="#style/Widget.Button"
android:text="Button" />
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#ffffffff"/>
<size
android:width="#dimen/shape_circle_width"
android:height="#dimen/shape_circle_height"/>
</shape>
1.add this in your drawable
2.set as background to your button
<gradient android:startColor="#ffdd00"
android:endColor="#color/colorPrimary"
android:centerColor="#ffff" />
<corners android:radius="33dp"/>
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp"
/>
Two things you need to do, if you want to make a custom button design.
1st is:
create a xml resource file in drawable folder (Example: btn_shape_rectangle.xml)
then copy and paste the code there.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="16dp"
android:shape="rectangle">
<solid
android:color="#fff"/>
<stroke
android:width="1dp"
android:color="#000000"
/>
<corners android:radius="10dp" />
</shape>
2nd is go to your layout button where you want to implement this design. just link up it.
Example:
android:background="#drawable/btn_shape_rectangle"
You can change shape color radius what design you want can do.
Hope it will works and help you. Happy Coding
Related
I've set up a button in my activity. Current code:
<Button
android:id="#+id/buttonSkills"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toEndOf="#+id/imageView2"
android:layout_toRightOf="#+id/imageView2"
android:onClick="buttonSkillsOnClick"
android:text="#string/skills"
android:textColor="#32c87d"
android:textSize="22sp" />
It currently has a white background to it. I would like the background to be transparent so that the user can only see the text.
When the user clicks the button, I just want a green border to appear around the button with no background.
I was wondering if this can be done with xml only?
You will need to make a drawable for when the item is selected, then apply that as the background. So in short, yes it is possible to do it with only xml, but you will need to make an additional file.
Something similar to this
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/button_selected" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="#drawable/button_focus" /> <!-- focused -->
<item android:drawable="#drawable/button_nothing" /> <!-- default -->
</selector>
button_selected.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ractangle">
<solid android:color="#00FF00"/>
</shape>
Yes you can. All you need to do is assign a State List drawable as a background to the button. The state list drawable inturn contains references to Shape Drawable.
Read all about it here (Shape Drawable and State List topic): http://developer.android.com/guide/topics/resources/drawable-resource.html
Make an xml file in drawable folder and paste this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="10dip" />
<stroke android:width="1dip" android:color="#fff" />
<gradient android:angle="-90" android:startColor="#color/primary" android:endColor="#color/primary_dark" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="10dip" />
<stroke android:width="1dip" android:color="#fff" />
<solid android:color="#FF7300"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="10dip" />
<stroke android:width="1dip" android:color="#fff" />
<gradient android:angle="-90" android:startColor="#color/primary" android:endColor="#color/primary" />
</shape>
</item>
</selector>
now set the background of a button like
android:background="#drawable/yourxml"
In my android app there is a rounded rectangle button with green colored background.
i did this using .xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#B5D397" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape>
and
android:background="#drawable/rounded_btn"
in layout file
but when i press button is wasn't showing any effect(no change is color) so i used
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Button view = (Button) v;
view.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
and color of button changes to dark green after pressing it. Till here everything is working fine, but problem is after releasing button color remains dark green. i want it to be like as it was before pressing.I referred few examples which says to use selector in .xml file i.e
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:color="#c0c0c0"
android:state_selected="true"/>
<item
android:color="#ffffff"
android:state_pressed="true"/>
<item
android:color="#9A9A9A"
android:state_focused="false"
android:state_pressed="false"
android:state_selected="false"/>
</selector>
Which also needs android:background="#drawable/btn_state"
but i have already used android:background=#drawable/rounded_btn
So how to give both effect together
i also tried using OnTouchListener
button.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// show interest in events resulting from ACTION_DOWN
if(event.getAction()==MotionEvent.ACTION_DOWN) return true;
// don't handle event unless its ACTION_UP so "doSomething()" only runs once.
if(event.getAction()!=MotionEvent.ACTION_UP) return false;
doSomething();
button.setPressed(true);
return true;
}
});
but this disables my OnclickListener() method and i dont want to use OnTouchListener()
i know this is silly but i am new to android
thanks a lot
You have to Create 3 xml files for that...
2 for Drawable Shapesand 1 for Drawable Selector
See Below Code..
button_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:left="2dp" android:top="2dp">
<shape>
<corners android:radius="10dp" />
<solid android:color="#22151515" />
</shape>
</item>
<item android:bottom="3dp" android:right="3dp">
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
<corners android:radius="10dp" />
<padding android:left="10dp"
android:right="10dp"/>
<stroke android:width="3px"
android:color="#color/border_pink" />
</shape>
</item>
</layer-list>
button_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:left="2dp" android:top="2dp">
<shape>
<corners android:radius="10dp" />
<solid android:color="#22151515" />
</shape>
</item>
<item android:bottom="3dp" android:right="3dp">
<shape android:shape="rectangle">
<solid android:color="#55fff000"/>
<corners android:radius="10dp" />
<padding android:left="10dp"
android:right="10dp"/>
<stroke android:width="3px"
android:color="#color/border_pink" />
</shape>
</item>
</layer-list>
button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_focused="true"
android:drawable="#drawable/button_selected"/>
<item
android:state_pressed="true"
android:drawable="#drawable/button_selected"/>
<item android:drawable="#drawable/button_normal"/>
</selector>
and finally....
android:background="#drawable/button_bg"
change code for drawable shapes as your need..
this may help you
Make two different shape xml. one with green color and other using another color..
And use them in selector.xml
<item android:drawable="#drawable/rounded_btn_green" android:state_selected="true"/>
<item android:drawable="#drawable/rounded_btn_green" android:state_pressed="true"/>
<item android:drawable="#drawable/rounded_btn_green" android:state_focused="true"/>
<item android:drawable="#drawable/rounded_btn"/>
Follow the below steps-
Define Button view in your main xml like this-
<Button
android:id="#+id/search_bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_selector_green"
android:text="Search"
android:textColor="#drawable/button_text_color_green"
/>
Create button_selector_green xml file in your drawable folder like this-
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/rounded_corner_transparent" android:state_pressed="true"/>
<!-- pressed -->
<item android:drawable="#drawable/rounded_corner_green"/>
<!-- default -->
</selector>
Create button_text_color_green xml file in your drawable folder like this-
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#48b28a" /> <!-- pressed -->
<item android:state_focused="true"
android:color="#FFFFFF" /> <!-- focused -->
<item android:color="#FFFFFF" /> <!-- default -->
</selector>
Create rounded_corner_transparent xml file in your drawable folder like this-
<?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/transparent" >
</solid>
<!-- view border color and width -->
<stroke
android:width="1dp"
android:color="#2b8c68" ></stroke>
<!-- If you want to add some padding -->
<padding
android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp" >
</padding>
<!-- Here is the corner radius -->
<corners android:radius="10dp" >
</corners>
</shape>
Create rounded_corner_green xml file in your drawable folder like this-
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#48b28a" >
</solid>
<!-- view border color and width -->
<stroke
android:width="1dp"
android:color="#2b8c68" >
</stroke>
<!-- If you want to add some padding -->
<padding
android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp" >
</padding>
<!-- Here is the corner radius -->
<corners
android:radius="10dp" >
</corners>
</shape>
Hope this will work for you. Happy Coding :)
Adding a click-effect on a custom button with padded corners
Please refer my answer in the above link.
We can acheive it by adding only one file in the drawable folder and refer that as background for the button.
Hope this will help somebody. One can use my solution and reduce the objects count when there is a concern for performance issue.
I am having few buttons added programatically and I want to set their text to be with black border and white inside, stroke, outline, or whatever it is called...
How can I do that? I think I need some style.xml but I can't find any.
I want the text to be just like this, simple
http://cdn.tutsplus.com/net/uploads/legacy/855_cssProperties/images/textStroke.jpg
1. create three .xml in res/drawable:
button_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<solid android:color="#FFFFFF" />
<corners android:radius="3dip" />
<stroke
android:width="1dip"
android:color="#android:color/transparent" />
button_focused.xml
<solid android:color="#FFFFFF" />
<corners android:radius="3dip" />
<stroke
android:width="1dip"
android:color="#android:color/transparent" />
button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="#drawable/button_normal.xml" android:state_window_focused="false"/>
<item android:drawable="#drawable/button_focused" android:state_focused="true"/>
2. set background with button_background.xml in your layout.xml or code
button.setBackgroundDrawable(getResources().getDrawable(
R.drawable.button_background.xml));
more information:http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
I am trying to achieve the effect which is shown in this following image:
In this image there is an edittext with round corner and internal shadow at top. I tried a lot but not success in getting shadow inside edittext.
I searched on this topic but all examples show shadow outside edittext border. I have no idea how can I achieve this.
The button and background image is already done, The only thing which is left is edittext shadow. If someone has already done this or know how to do this please share with me. Any help whould be appreciated.
Got like this
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:centerY="0.2"
android:startColor="#FFBDBDBD"
android:centerColor="#65FFFFFF"
android:endColor="#00FFFFFF"
android:angle="270"
/>
<stroke
android:width="1dp"
android:color="#C3C3C3" />
<corners
android:radius="25dp" />
</shape>
Just create an xml file in your drawable folder name as round_corner.xml.And add this following code.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:radius="3dp"
/>
<solid
android:color="#android:color/white"/>
</shape>
At Last you add this xml in background property of your Edittext as follows:-
<EditText
android:id="#+id/ed1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_corner"
/>
Done..Definitely it works..
1.) Create rounded_edittext.xml file in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="15dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
<stroke android:width="1dip" android:color="#FF0000" />
</shape>
2.) Put below code in styles.xml file placed in values folder
<style name="largeEdittextText">
<item name="android:textAppearance">#android:style/TextAppearance.Large.Inverse</item>
<item name="android:textSize">15dp</item>
<item name="android:singleLine">true</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:paddingLeft">5dp</item>
<item name="android:background">#FFB90F</item>
<item name="android:textColor">#android:color/black</item>
</style>
3.) Apply both on edittext in layout file
<EditText
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:hint="#string/login_userHint"
android:text="admin"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:textAppearance="#style/largeEdittextText"
android:background="#drawable/rounded_edittext">
</EditText>
if you want to make the border of EditText Round and curve, then just paste this code in Drawable/mystyle.xml (create this xml file) .
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">
<stroke android:width="1dp"
android:color="#c8c8c8"/>
<corners android:radius="11dp" />
</shape>
Now in your EditText link this file as
android:background="#+drawable/mystyle"
Normal button looks like:
Now, please let me know, How can i make a simple button same as an attached image button (i.e. button corner shape is round and also there is no gap between two buttons)
1- create shapes (with desired colors) for pressed and released states
To create the shapes I would suggest this great website the will do it for you: http://angrytools.com/android/button/
drawable\botton_shape_pressed.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/pressed_button_background"
android:endColor="#color/pressed_button_background"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
drawable\botton_shape_released.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/released_button_background"
android:endColor="#color/released_button_background"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
2- create a selector for the two shapes
drawable\botton_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/botton_shape_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/botton_shape_pressed"
android:state_selected="true" />
<item android:drawable="#drawable/botton_shape_released" />
</selector>
3- use the selector for the button
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/test"
android:textColor="#color/blue_text"
android:onClick="testOnClickListener"
android:background="#drawable/botton_selector" />
9-patch would work fine here, but I try to avoid them since it's hard for me to do them :(
You can try having a selector and using a shape for each state:
The shape would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#AAFFFFFF"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
You need to create a 9-patch drawable. In order to have no gap (margin) between the buttons you need to create the appropriate layout in XML and set the margin to 0.
look for foursquared source code and look for SegmentedButton.java file, this is the file that implement these buttons shown in the image.
Create a Nine patch drawable which is easy with draw9patch (part of android/tools) and then apply styles and themes... the tutorial at this link (Androgames.net) should get you started.
to style the text you can add this to the strings.xml
<style name="ButtonText">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ffffff</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">3dp</item>
<item name="android:textSize">30dp</item>
<item name="android:textStyle">bold</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">2</item>
</style>
and call it in the main.xml button
style="#style/ButtonText"
and an alternative method you can play with is creating in #drawable/btn_black with the following...
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#343434" />
<stroke
android:width="1dp"
android:color="#171717" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#343434"
android:endColor="#171717"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#171717" />
<corners
android:radius="4dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
You can also use ImageView in your xml file and than give onClickable and onFocusable true and then create onClick event method on backend code and give the name of the method on xml , so that instead of dealing with all shape or button issues you just put the imageview there and make it act like a button.Here is sample code for you
<ImageView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:onClick="testClickEvent"
android:paddingRight="8dip"
android:paddingBottom="8dip"
android:src="#drawable/testImg"/>
As I said on backend side create method with sign like this and this will do the job
public void testClickEvent(View v){}
Then implement what you wanna do in this method
button_primary.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#color/background"
android:startColor="#color/background" />
<corners android:radius="1dp" />
<stroke
android:width="2px"
android:color="#color/colorPrimary3" />
</shape>
call
style="#style/button_primary"