Questions tagged [android-button]

questions about the android.widget.Button element. This element can be used on activities.

On Android, buttons can be generated programmatically in Java code or by using xml layouts. Usually a listener(OnClickListener) is set on the Button to receive an event when the user touches the Button. The listener can be set in code or by using the android:onClick attribute in the xml layout, setting it to point to a method written in the Activity class.

Initial help

2399 questions
155
votes
10 answers

How to add a button to a PreferenceScreen?

I'm quite new to Android Development and just came across Preferences. I found PreferenceScreen and wanted to create a login functionality with it. The only problem I have is that I don't know how I could add a "Login" button to the…
Van Naaktgeboren
  • 1,551
  • 2
  • 10
  • 4
127
votes
11 answers

Android button with icon and text

I have some buttons like this in my app:
127
votes
8 answers

Change Screen Orientation programmatically using a Button

I think this is implementable since screen rotation behaviour can go up to the application level.
Sam
  • 4,521
  • 13
  • 46
  • 81
111
votes
10 answers

Android: how to handle button click

Having a solid experience in non-Java and non-Android area, I'm learning Android. I have a lot of confusion with different areas, one of them is how to handle button clicks. There are at least 4 way of doing that (!!!), they are briefly listed…
Budda
  • 18,015
  • 33
  • 124
  • 206
107
votes
8 answers

Android Fragment onClick button Method

I'm trying to invoke the method in my onClick (View v) XML, but does not work with Fragment. This is the error. 01-17 12:38:36.840: E/AndroidRuntime(4171): java.lang.IllegalStateException: Could not find a method insertIntoDb(View) in the activity…
user3160725
  • 1,801
  • 3
  • 15
  • 14
94
votes
14 answers

How do I open a new fragment from another fragment?

I tried making a navigation between fragments. I've got the NewFragment.java with the new fragment working. My problem is: How do I make this onClickListener run NewFragment.java correctly? button.setOnClickListener(new OnClickListener() { …
Hultan
  • 1,409
  • 1
  • 15
  • 28
89
votes
7 answers

setEnabled() vs setClickable(), what is the difference?

Until now, when I wanted to stop the user from pressing the button, I would set the button.setClickable(false); and usually change the text to some kind of grey colour (to let the user know that the button is disabled). Today I stumbled upon the…
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
87
votes
14 answers

Android button background color

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,…
user2260040
  • 1,275
  • 1
  • 13
  • 26
84
votes
10 answers

Rounded Button in Android

I want to create rounded buttons in an Android program. I have looked at How to create EditText with rounded corners? What I want to achieve is: Rounded Edge Buttons Change Button background/appearance on different states (Like Onclick, Focus) Use…
ControlAltDelete
  • 3,576
  • 5
  • 32
  • 50
83
votes
2 answers

How to set focus to a button widget programmatically?

Is it possible to set a focus to a button widget which lies somewhere down in my layout? onCreate of the activity my control/focus should be on that button programmatically.
Vinayak Bevinakatti
  • 40,205
  • 25
  • 108
  • 139
80
votes
24 answers

How to change the color of a button?

I'm new to android programming. How do I change the color of a button?
74
votes
10 answers

Material design button with border

I know how to make Material Design button with color fill: style="@style/Widget.AppCompat.Button.Colored" And no-bordered transparent button: style="@style/Widget.AppCompat.Button.Borderless.Colored" However, is there a way to make Material design…
71
votes
3 answers

How is using OnClickListener interface different via XML and Java code?

Possible Duplicate: Difference between OnClick() event and OnClickListener? I'm semi-new to Android development and when I first started I tried to avoid using the xml layout by any means necessary so some of my earlier projects involve buttons…
SmashCode
  • 4,227
  • 8
  • 38
  • 56
71
votes
8 answers

background color on Button in Jetpack Compose

Button(backgroundColor = Color.Yellow) { Row { Image(asset = image) Spacer(4.dp) Text("Button") } } I can not figure out why I can't use background color on Button. I followed the Compose Layout codelabs. There is a…
71
votes
6 answers

How to create rounded border Button using Jetpack Compose

I need to add border with rounded corner in Button using Jetpack Compose Like :