Android - Changing the size of the Checkbox itself - android

I did my homework and this question has been asked a few times, but never answered with a solution to the problem. The question is, how do you change the size of the checkbox button in a checkbox compound button?
In my case I have a checkbox with a custom button attribute pointing to a selector xml file containing items for each possible state pointing to png images. I want to be able to specify in dp the size that these images are displayed as the button for the checkbox.
The answer to this question is NOT to change the android:layout_width of the checkbox itself. Anyone know how to do this?
Also, things I've tried include adding widths and heights to the selector and items. I've tried adding my selector to a Button and resizing the button (which works for the button alone), but I can't figure out how to specify to the CheckBox that it should use that Button xml.

I just ran into this problem myself. My checkbox has no text, and in that case this works well:
set
android:background="#my_selector_drawable"
instead of the button attribute. To avoid the standard button on top of the image, set
android:button="#null"
Now you can set the size of the checkbox with the normal android:layout_width & android:layout_height.
If you want a checkbox with text as well, this wont work

Well for now the best I can do seems to be to build my own checkbox using a button by keeping a boolean for the state that gets inverted in the OnClickListener and calling setBackgroundResource to swap between the "checked" and "unchecked" drawables.
Meh. At least I can resize the button to be exactly what I want. Hopefully someone will come up with a better way to do it.

Related

Android ExpandableList Header with spinner

I'm developing an application and I am facing a problem using ExpandableListView. What I'm trying to do is, in GroupHeader, not only show the group name, but also an spinner with options. That's because I want to show the football second division games in the list but, also, give the option to choose the round, in case the user wants to check older/future games. SO far I have that
As you can see both, title and spinner, shows. Also you can see the arrow on the right which is supposed to expand the list. Problem is that, if I click, only spinner opens, group expand button doesn't. So, here is my question, how can I make both of them work depending on where you click (one or another)??? Is that possible?
Also I must say that if I only place the TextView with the group name works perfect. If I only place the spinner, the problem persists. So I'm guessing that's a focus problem.
Btw: grey areas are the layout backgrounds, so no, they are not hiding behind the button.
I found the solution, I just neede to add this line android:descendantFocusability="blocksDescendants" to the Main Layout of the xml where I define the GroupHeader elements.

Show selected button

I have a group of buttons which enable user to select certain views on the touch screen.
I want to have the user know which view is active by showing a halo (or any other style) around the button. I mean when the button is clicked it's normal state is changed to different style but it is still normal.
I googled and checked in stackoverflow, that it is not possible to change the style at runtime.
How can I achieve the desired effect?
I have some silly ideas which I won't implement unless as last resort, like making two buttons at same positions and changing their visibility.
Or I can put each button in it's own linear layout and then set the background color of each of them, if it is possible.
Or some ImageButton manipulation maybe.
I have already overridden the default style for button for normal pressed states.
And setting focus(when in focusInTouchMode) causes problem, so that's a NO (already tried that).
Even if style can't be changed, please advise some tip to achieve the effect, it's not necessary to do it the style way. I just want o let the user know which view is selected through buttons.
use state list and set its focussed state drawable as the button with a ring around it and then at runtime say button.requestFocus(). see here for more on state list...
Go for selector xml background for each button. Best Resort
Check this link
How to set image button backgroundimage for different state?
Hpoe this helps
or you can use like ::
Button button;
public void onClick(View v)
{
button.button.setBackgroundColor(**color**);
button.setBackgroundResource(**res**)
}

Drawable on simple button

How can a button (Button) receive a drawable and center it on the button without the text?
If you can not do this, how then do to the background does not "stretch" button at all?
The problem is that for some button have icon and text, for others only the icon and the third type only text! So I have to use an object alone, more stylish, rather than several different classes.
Google needs to improve this architecture! If I want a button with or without text, occluding the center with the image, it is my problem, I should be able to do!
For your first request: use ImageButton if you wanna have Both, text and drawable, or combinations of that I think you have to subclass button yourself. You can look inside the code of TabWidget how to do that (because TabWidget can already have both but was intended to start Activities)
Use a layout, such as AbsoluteLayout, LinearLayout, or RelativeLayout with a TextView and ImageView to create your custom clickable layout and views. Also check this article about layout reuse.

How I can change the Background in runtime in Android?

I want to make a simple program with 2 Radiobutton (rd1 and rd2), what can change background to picture s1, or s2, depend on what was selected. How I can make it? I tried background.setBackground (background is my RadioGroup's name), but it didn't work.
try this for changing android wallpaper.
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/SetWallpaperActivity.html
and if you want change the background for the current activity means
if your layout is lay means then,
lay.BackgroundDrawable(R.drawable.abc);
in onClick listenerof ur radio button
sure it will help you dude..let me know what happened...
Thank you.

iphone-style text edit on android

I'm trying to make iPhone-style EditText element on android.
The one that will have an additional clear button appear on the right after text input.
Adding a new button is not a problem, but I'm a bit stuck with another thing.
A button occupies some space on the right part of EditText, and now characters display beneath the button. How to change maximum shown length of input for EditText?
I want EditText width to be N pixels, and editable area to be N-M pixels.
EditText.setWidth changes width for whole edit box.
EditText.setEllipsize should be the proper solution, but docs are empty, and as I see it truncates text based on some String value.
Applying a LengthFilter cut's the input length to number of characters.
Thanks in advance.
I suspect that android:drawableRight will save you a lot of pain.
Seems I've found a solution.
EditText.setPadding(l,t,r,b) seems to work fine, applying only for editable area
Try this : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/
This is a very old question, but thought I'd add my two cents for kicks. I'd probably use a 9 patch for this and set the content area to stop the text before it hits the button area.
This would require creating a custom view so that you can add a button in the desired position using relative layout so that it can be clicked to clear the edittext.
Alternatively you can use the compound drawables, but you would need to implement something like this
Handling click events on a drawable within an EditText so that you can handle the click events. Keep in mind that I doubt the button states (eg the down state) will work using this method.

Categories

Resources