Android customized button; changing text color

Create a stateful color for your button, just like you did for background, for example: <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <!– Focused and not pressed –> <item android:state_focused=”true” android:state_pressed=”false” android:color=”#ffffff” /> <!– Focused and pressed –> <item android:state_focused=”true” android:state_pressed=”true” android:color=”#000000″ /> <!– Unfocused and pressed –> <item android:state_focused=”false” android:state_pressed=”true” android:color=”#000000″ /> <!– Default color –> <item android:color=”#ffffff” /> … Read more

Android Material Design Button Styles

I will add my answer since I don’t use any of the other answers provided. With the Support Library v7, all the styles are actually already defined and ready to use, for the standard buttons, all of these styles are available: style=”@style/Widget.AppCompat.Button” style=”@style/Widget.AppCompat.Button.Colored” style=”@style/Widget.AppCompat.Button.Borderless” style=”@style/Widget.AppCompat.Button.Borderless.Colored” Widget.AppCompat.Button: Widget.AppCompat.Button.Colored: Widget.AppCompat.Button.Borderless Widget.AppCompat.Button.Borderless.Colored: To answer the question, the style … Read more

Why is my Button text forced to ALL CAPS on Lollipop?

I don’t have idea why it is happening but there 3 trivial attempts to make: Use android:textAllCaps=”false” in your layout-v21 Programmatically change the transformation method of the button. mButton.setTransformationMethod(null); Check your style for Allcaps Note: public void setAllCaps(boolean allCaps), android:textAllCaps are available from API version 14.

In Android, how do I set margins in dp programmatically?

You should use LayoutParams to set your button margins: LayoutParams params = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT ); params.setMargins(left, top, right, bottom); yourbutton.setLayoutParams(params); Depending on what layout you’re using you should use RelativeLayout.LayoutParams or LinearLayout.LayoutParams. And to convert your dp measure to pixel, try this: Resources r = mContext.getResources(); int px = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, yourdpmeasure, … Read more

How to make the corners of a button round?

If you want something like this here is the code. 1.Create a xml file in your drawable folder like mybutton.xml and paste the following markup: <?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=”3dip” /> <stroke android:width=”1dip” android:color=”#5e7974″ /> <gradient android:angle=”-90″ android:startColor=”#345953″ android:endColor=”#689a92″ /> </shape> </item> <item android:state_focused=”true”> <shape android:shape=”rectangle” … Read more

How to start new activity on button click

Easy. Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class); myIntent.putExtra(“key”, value); //Optional parameters CurrentActivity.this.startActivity(myIntent); Extras are retrieved on the other side via: @Override protected void onCreate(Bundle savedInstanceState) { Intent intent = getIntent(); String value = intent.getStringExtra(“key”); //if it’s a string you stored. } Don’t forget to add your new activity in the AndroidManifest.xml: <activity android:label=”@string/app_name” android:name=”NextActivity”/>