Can I remove border of RadioButton and I have RadioButtons like bellow :
I see a lot of question and I used from android:buttonTint="" and style ... but don't work .
You can't remove that using the radiobutton.
what you can do is set it to the same color as your background,
or create a custom radiobutton XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="false"
android:drawable="#drawable/your_radio_off_image_name" />
<item android:state_checked="true"
android:drawable="#drawable/your_radio_on_image_name" />
</selector>
use that XML in your layout:
<RadioButton
android:id="#+id/radiobutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/custom_radiobutton"/>
more info and examples about custom xml:
Adding custom radio buttons in android
remove default radio button checkbox when using a custom selector
Another option is to use a toggle instead of radiobutton, and just change the drawable onToggle.
You will need to create a custom radio button to change the style in that way. Read this article if you want to learn how to do it. Good luck.
No, you can't remove this.You can custom radio button.
Related
This question already has answers here:
Adding custom radio buttons in android
(12 answers)
Closed 6 years ago.
I want some ImageViews to work as RadioButtons. But I don't want the mini-button of a RadioButton to select it; I want this mini-button to disappear, and the ImageView to be the entire button. Thus, a solution like the following one is not good.
<RadioButton
android:id="#+id/myId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/myIcon"/>
Is there a widget or something which I can use to use ImageViews as RadioButtons, or should I program myself all the logic of the buttons?
I will suggest to create your custom radio button. check this answer of Evan Bashir
you can try with button attribute like bellow.
<RadioButton
android:id="#+id/myId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/myIcon"/>
or through grammatically.
myRadioButton.setButtonDrawable(resourceId or Drawable);
and you can change the images while selecting the RB through the following xml file...save this file in drawable folder and call it in the button attribute or grammatically .
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="#drawable/star_down" />
<item android:state_checked="false" android:drawable="#drawable/star" />
</selector>
Just set the image in the android:background of the RadioButton's XML declaration.
Also set the android:button to transparent: android:button="#android:color/transparent"
If you want to have different states - create a selector with different images for the two states.
I'm using a standard button in my layout:
<Button
android:id="#+id/earlier_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="earlier"/>
And I figured out how to change it's color without changing it's default style:
earlierButton = (Button) findViewById(R.id.earlier_button);
earlierButton.getBackground().setColorFilter(getResources().getColor(R.color.red_500), PorterDuff.Mode.MULTIPLY);
My question is now, how can I set a new selector/ripple or change the color of the current one? Does anyone know the default theme/style, which needs to be overwritten for that? Talking about these buttons:
You can set selector.
See this link for detail. https://stackoverflow.com/a/28431028/850347
You have Button,
<Button
android:id="#+id/earlier_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="earlier"/>
And you may have selecor,
btn_selecor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/btn_normal" android:state_pressed="false"/>
<item android:drawable="#drawable/btn_pressed" android:state_pressed="true"/>
</selector>
btn_normal, btn_pressed is png images.
Note that this btn_selecor.xml must be placed folder name "drawable"
Finally, set selector to your button programmatically.
Drawable buttonDrawable = getResources().getDrawable(R.drawable.btn_selector);
buttonDrawable.mutate();
btn1.setBackground(buttonDrawable);
Edit1:
Sure, you can set android default button selector by using code below.
In this case, you don't need to make your own selector.
Drawable buttonDrawable = getResources().getDrawable(android.R.drawable.btn_default);
buttonDrawable.mutate();
btn1.setBackground(buttonDrawable);
I have some RadioButtons inside a RadioGroup and I am using custon icons to replace the typical radio "dot".
I have my normal state (checked=false) and checked state (checked=true) sorted.
However, when tapping/pressing the RadioButton, there is a grey-ish highlight colour in the background, that is round in shape (to match the original radio dot).
How can I customise this highlight colour? I tried using "android:state_pressed" but that didn't seem to do anything? (Well, I tried adding a shape, as mentioned here: https://stackoverflow.com/a/14602078/601869)
Ideally, I'd like the shape to match that of the icon (well, most probably be a bit bigger) and change the colour.
Selector XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="#drawable/rounded" />
<item android:state_checked="true" android:drawable="#drawable/rounded_checked" />
</selector>
RadioButton XML:
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/radioButton01"
android:button="#drawable/rounded_radio_select" />
try changing
android:button="#drawable/rounded_radio_select" />
to
android:background="#drawable/rounded_radio_select"
android:button="#android:color/transparent"/>
Maybe this is the same issue Adding custom radio buttons in android
I'm using a check-box in my project, but I'm not able to eliminate the left padding, so the alignment isn't right.
Anyone know how to eliminate that left padding?
After some research I found out that, this specific margin is in the drawable of the check-square. So I suppose that the only solution is to create a custom drawable
This is because the drawable used by Android Checkbox has its own margin.
So to avoid it you''ll have to create your own checkbox with a custom drawable and icons for checked and unchecked states.
1> Create a custom selector for your checkbox like:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="#drawable/ic_unchecked" />
<item android:state_checked="true" android:drawable="#drawable/ic_checked" />
<item android:drawable="#drawable/ic_unchecked" /> <!-- default -->
</selector>
2>Then in your xml add a normal check box ,set drawable and button properties as null and assign your selector as the left drawable of your checkbox.Also give a drawable padding to give some padding between checkbox icon and text.
<CheckBox
android:id="#+id/chk_terms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:button="#null"
android:drawableLeft="#drawable/custom_checkbox"
android:drawablePadding="#dimen/margin_left_right"
android:text="#string/i_agree"
android:textSize="#dimen/text_size_small"
/>
NOTE ->
This soln also solve the padding problems of checkbox on and above android 4.2. which is also referred HERE
So I have an image button and I want to have two states on it. It will work like a bookmark button which has two states. If the user presses the button then it changes the image and if it re-presses the button then I want the original image back.
Is that possible? Is there an easier way using another type of button?
Thank you
Try changing the topic to :"What kind of Button can toggle/change states?"
Seems like you need ToggleBotton
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="26dp"
android:background="#color/button_colors"
android:button="#null"
android:textOff="#null"
android:textOn="#null" />
And this xml defines the colors/images of the button at rest/pressed states, put it in res/color/button_colors.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="#drawable/button_rest"/>
<item android:state_checked="true" android:drawable="#drawable/button_on" />
</selector>
Yes, you can use regular buttons also. First make a selector XML file in the res/drawable directory. Example:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_selected="true"
android:drawable="#drawable/selectedimage"/>
<item android:state_enabled="true" android:state_selected="false"
android:drawable="#drawable/notselectedimage"/>
</selector>
In the button definition in the layout xml, you just add this attribute:
android:background="#drawable/myselectorxmlfile"
And then you programmatically set the selected states yourself (in a onClickListener) and the button images will change background state.
button.setSelected(true) // or false;
These links might help you..
http://developer.android.com/resources/tutorials/views/hello-formstuff.html
and
http://developer.android.com/reference/android/widget/ToggleButton.html
I guess you can use Toggle Button and hope it'll solve your issue.
Just have a look at a simple xml code of it:
<ToggleButton
android:id="#+id/tglbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="ON"
android:textOff="OFF"
/>
And Just check the answer given here in this link:
Android: Specify two different images for togglebutton using XML
Also,
I've posted a simple tutorial about Toggle Button. Just have a look at my humble blog if you find it helpful. Here is link: http://androiddesk.wordpress.com/2012/03/10/toggle-button-in-android/