android-button

How do I change the text color of a Button?

怎甘沉沦 提交于 2019-11-28 22:43:30
How do I change the text color of a Button? ρяσѕρєя K try this: button.setTextColor(getApplication().getResources().getColor(R.color.red)); //TAKE DEFAULT COLOR or button.setTextColor(0xff0000); //SET CUSTOM COLOR or button.setTextColor(Color.parseColor("#ff0000")); and in xml : <Button android:id="@+id/mybtn" android:text="text textx " android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textColor="#ff0000" /> <-- SET TEXT COLOR HERE --> Use the android:textColor property. <Button android:layout_width="wrap_content" android:layout_height=

Rounded corners on material button

那年仲夏 提交于 2019-11-28 22:18:19
问题 I'm following the tips from questions like this to create a button style like suggested on Material Design. However, I need to change the corner radius and haven't been able to do so by inheriting Widget.AppCompat.Button.Colored style and setting the radius parameter. How can I have the same style but with rounded corners? 回答1: You need to inherit that style. Add into your styles.xml: <style name="AppTheme.RoundedCornerMaterialButton" parent="Widget.AppCompat.Button.Colored"> <item name=

Android button background color

别等时光非礼了梦想. 提交于 2019-11-28 17:10:52
I am trying to set the background color of a button in my app and I am unable to achieve the result that I want... The color that I am trying to set is holo_green_light(#ff99cc00) . In order to do it, I am using setColorFilter(0xff99cc00, PorterDuff.Mode.MULTIPLY); The color that I get is not the holo_green_light but a mix of lightgrey and holo_green_light . I have tried using the LightingColorFilter without much success. Is there a way to do it programatically, so that the button appears like a button and not a flat rectangle with the color that I need. Buttons are more complex than just

What is the “state_focused” state for a Button?

痞子三分冷 提交于 2019-11-28 16:52:29
I would like a Button background to remain a certain color after the button is clicked, and change colors again when some other button is pressed. I thought this was the "state_focused" state. But the only two states I seem to have for my Button is pressed or not pressed. Do I understand the state_focused state correctly, or is my StateListDrawable (see below) wrong? <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_pressed="false"><shape> <solid android:color="#00ff00" /> </shape></item

How do I set the disabled color of a button with AppCompat?

独自空忆成欢 提交于 2019-11-28 16:42:00
I use this style to change the background color of my Button : <style name="AccentButton" parent="Widget.AppCompat.Button.Colored"> <item name="colorButtonNormal">@color/colorAccent</item> <item name="android:textColor">@color/white</item> </style> And in layout: <Button android:id="@+id/login_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/fragment_login_login_button" app:theme="@style/AccentButton"/> It works. But when I call setEnabled(false) on this Button , it keeps the same color. How can I manage this case? ianhanniballake You aren

Changing the position of radio button

夙愿已清 提交于 2019-11-28 14:18:30
Can I change the radio button position from left to right. I mean the green selected button will be on the right and the text on its left. Is it possible? (by default button left, text right) It should be possible to use getCompoundDrawables() and setCompoundDrawables() to rearrange the drawables around the text. To go one step further, perhaps you could perhaps implement your own CheckBoxRight widget based on CheckBox which did that in the onDraw() method after calling super.onDraw(). A final alternative would be to build your own widget directly from TextView and just setCompoundDrawables()

Android 5.0 - ProgressBar cannot be displayed over a Button

家住魔仙堡 提交于 2019-11-28 13:16:16
I think the title is pretty explicit about my problem... So here is my layout : <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/button_action" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Login" /> <ProgressBar android:id="@+id/progress_bar" android:layout_width="50dp" android:layout_height="50dp" android:layout_centerInParent="true"/> </RelativeLayout> On android SDKs < 21, no problem, the ProgressBar is correctly displayed over the Button and centered in the Button. But on Android 5.0

Defined custom shape for button in xml. Now I want to change the color dynamically. How?

做~自己de王妃 提交于 2019-11-28 13:07:07
I have this: round_button.xml <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="oval"> <solid android:color="#dec60000"/> <size android:width="150dp" android:height="150dp"/> </shape> </item> <item android:state_pressed="false"> <shape android:shape="oval"> <solid android:color="#860000"/> <size android:width="150dp" android:height="150dp"/> </shape> </item> My Button: <Button android:id="@+id/incrementBTN" android:layout_width="wrap_content" android:layout_height="wrap_content"

How to set button by a contour polygon? Android

青春壹個敷衍的年華 提交于 2019-11-28 12:24:47
There are two adjacent graphic buttons. If I use the method of calculation of the coordinates touch TouchEvent , I have to create a large array of coordinates. Maybe there is another method? Probably not the best solution but you could overlap two buttons each representing a part of the image(the black or white) and make the rest of the Button 's image transparent(the images will have the same dimensions for both buttons). You'll also need to extend the Button class to override how the onTouchEvent method handles the touch events, depending on the point where the touch happened being a

Android - Count Power button clicks and Start Activity

旧时模样 提交于 2019-11-28 11:50:28
I used the below code, but didnt find the solution. MyReceiver.java: import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; import android.widget.Toast; public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.v("onReceive", "Power button is pressed."); Toast.makeText(context, "power button clicked", Toast.LENGTH_LONG) .show(); } } and MainActivity.java: import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class