CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2023-09-17
by Simin Ghasemi

Original Post

Original - Posted on 2013-06-20
by devunwired



            
Present in both answers; Present only in the new answer; Present only in the old answer;

As told [here][1] you can declare it in the constructor like this:
Button button = new Button(context, null, android.R.attr.borderlessButtonStyle); ImageButton imageButton = new ImageButton(context, null, android.R.attr.borderlessButtonStyle);



[1]: https://stackoverflow.com/questions/17027462/android-imagebutton-without-border-but-still-with-click-indication
As has been mentioned, the `borderlessButtonStyle` built into the default themes on API11 and above is the simplest way to achieve this effect. You mentioned you are creating your buttons in Java code instead of XML, so there are two options depending on how you need to apply the style.
**Option #1: Add it to the theme**
If all the `Button` or `ImageButton` instances in your application (or at least within the Activity) need to have this style applied, add the styling to your theme instead:
<resources> <style name="AppTheme" parent="android:Theme.Holo.Light"> <!-- Default style for ImageButtons --> <item name="android:imageButtonStyle">?android:borderlessButtonStyle</item> <!-- Default style for Buttons --> <item name="android:buttonStyle">?android:borderlessButtonStyle</item> </style> </resources>
With this theme applied to your Application or Activity, you won't have to declare the style of each element, you can just declare them as
Button button = new Button(context); ImageButton imageButton = new ImageButton(context);
And the styling will be pulled from the theme.
**Option #2: Declare it in the constructor**
If only a couple buttons need to be styled this way, you can pass the style attribute you want to apply directly to each view, like so:
Button button = new Button(context, null, android.R.attr.borderlessButtonStyle); ImageButton imageButton = new ImageButton(context, null, android.R.attr.borderlessButtonStyle);
This version supplies a different default style attribute for the widget to use.

        
Present in both answers; Present only in the new answer; Present only in the old answer;