The Android Design Guidelines say to use borderless buttons (see picture below), but don't really explain how. Someone asked this same question a few weeks ago here: How to create standard Borderless buttons (like in the design guidline mentioned)? and there was an answer marked as "the" answer, but I am still lost and I don't see a way to add comments to a question that has been "closed"
The answer-er said
"Look into the theme attributes
buttonBarStyle
,buttonBarButtonStyle
, andborderlessButtonStyle
"
but I still can't figure out how to actually use those things. I Googled around a bit and couldn't find anything so I figured I'd just ask the question again, and hopefully someone can provide a little more detail on how this works.
To define the click event handler for a button, add the android:onClick attribute to the <Button> element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The Activity hosting the layout must then implement the corresponding method.
Creating Anonymous View.OnClickListenerLink the button from the XML by calling findViewById() method and set the onClick listener by using setOnClickListener() method. setOnClickListener takes an OnClickListener object as the parameter. Basically it's creating an anonymous subclass OnClickListener in the parameter.
According to official documentation of Buttons provided by Android. You can first create Button in your . xml file. And then cast your button with Button Class and set ClickListener.
I thought I had this solved when I looked here a few weeks ago and noticed the answer about using a transparent background but it isn't quite good enough because it prevents the button from being highlighted when pressed.
Also, setting the style to Widget.Holo.Button.Borderless
isn't appropriate because it makes the button boundaries to big.
To figure this out once and for all, I check the android source code for the standard Calendar app and found that it uses the following:
android:background="?android:attr/selectableItemBackground"
Doing it this way ensures the button is borderless and the correct size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With