Checkbox with custom background and no border doesn't check - android

I have a custom checkbox with no border and custom background:
<CheckBox
android:id="#+id/ricordami"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:background="#color/gray"
android:button="#android:color/transparent" />
but when i launch my app, checkbox on click doesn't show check flag. How can i fix it?

Related

How to resize image of checkbox in android?

I am adding image for a CheckBox widget (that is instead of the default one for both clicked and unclicked ones in .xml file using selector) it's getting added, but the image can't be resized into a smaller one and remains in its original size.
How could I decrease the image size?
The code I used to create the CheckBox is
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:button="#drawable/check_box"
android:drawablePadding="20dp"
android:text="check box text"
android:textColor="#color/labelColor" />
Set the android:button field to null and to set the checkbox as the android:background field of the checkbox
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#null"
android:drawablePadding="20dp"
android:text="check box text"
android:background="#drawable/check_box" />
To set the android:button field to null and to set the checkbox states as the android:background field of the checkbox.
Your code would then become:
<CheckBox
android:id="#+id/cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#null"
android:background="#drawable/check_box"
android:drawablePadding="20dp"
android:text="check box text"
android:textColor="#color/labelColor" />
#berry: Please set android:button="#null" and set this in your android:background .
android:button="#null"
android:background="#drawable/check_box"
CheckBox doesn't respect the size of the android:button drawable when the layout width and height are set to wrap_content. So use android:background .

CheckBox doesn't display selector on black background?

I'm trying add a CheckBox, the problem is the background of LinearLayout is black and the selector of CheckBox doesn't display to check. Checkboxes are Brinde and Entrega Futura in picture.
How could I solve it ?
<CheckBox
android:id="#+id/cbEntregaFutura"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Entrega Futura"
android:textColor="#FFF"
android:layout_weight="1"
/>

Want ToggleBotton to NOT show ON/OFF text

Im trying to make my ToggleBotton to NOT show the ON/OFF cause I'm using a backround of Green/Red that show if it's on or off and the text just messes things up..
Thank you.
<ToggleButton
android:id="#+id/toggle"
style="#style/AppBaseTheme"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#drawable/toggle_selector"
android:layout_below="#+id/rel1"
android:checked="true" />
What about just setting the text for On and Off to be an empty string like
android:textOff=""
android:textOn=""

Custom Spinner view under Button

I have a Button that, when clicked, calls a Spinner. The Spinner has a custom view but the layout goes in the middle of the page instead of under the Button.
This is what it should look like:
Instead it looks like this:
How can I show the view under my Button like the first image? Here is my button and spinner .xml
<ImageButton android:id="#+id/window_recent_menu"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:background="#null"
android:src="#drawable/menu_btn"
android:contentDescription="#string/contentDesc"
android:visibility="gone"/>
<Spinner android:id="#+id/window_recent_menu_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:visibility="gone"/>
Thanks
P.S the android:visibility="gone" for the ImageButton is for certain views. That does not apply for the view seen above.
What you really want here is a PopupMenu, not a Spinner. (support package)

How to create an overlay view in Android which toggles on button click

I want to create and overlay view when a button is clicked. Something like clicking smileys button in Whatsapp.
I have created a framelayout with default visibility as GONE and added an onclick listener on smiley button to toggle its visibility.
My layout XML:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<ImageView
android:id="#+id/smileyButton"
android:layout_width="24dip"
android:layout_height="48dip"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:contentDescription="#string/contactIconContentDescription"
android:src="#drawable/emo_im_happy" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/smileyButton" >
<TextView
android:id="#+id/chat_smiley_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white" />
</FrameLayout>
</RelativeLayout>
I have added onClickListener to smileyButton which toggles visibility of chat_smiley_list.
Other than some positioning problems, I am not sure whether this is the best way to do it.
I think you could use a Context Menu: documentation

Categories

Resources