I want a widget that behaves like a togglebutton and can have its background color changed from code in runtime. Is there such a widget out there?
Or can someone put me in the right direction of how to develop av widget with the desired features? Samples?
Use setBackgroundColor(color). It is inherited from the View class.
Related
I am wondering if there is a way to create a Seekbar (slider) widget for an app. I know how to create a Seekbar in my app activity but how can I change this Seekbar-value with a widget? I tried to find some information about it in the internet but I couldn't find anything. So I don't know if it is even possible to create Seekbar widgets...
In advance thanks for your answer!
If by "widgets" you mean app widgets, SeekBar is not one of the supported views that you can use in an app widget.
you can use a Progressbar with custom style to show a progress value in your widget.
I'm trying to make a widget which is a togglebutton like the ones in the android control widget (the quicksettings for wlan, bluetooth etc.).
Here's how it looks (#Control Widgets)
Does anyone know if this layout is contained in the android sdk or if not how I can make a layout just like that one?
I've already tried some things but I don't know how do to the stroke at the bottom.
Regarding to your issue I searched a little bit deeper.
See: https://developer.android.com/guide/topics/appwidgets/index.html
These are the classes which you can use with an appwidget to implement in your layout there is no such thing like a toggle button, but an imagebutton which I think us exactly what Google is using for the "toggle buttons". Take a closer look on the imagebutton :
https://developer.android.com/reference/android/widget/ImageButton.html
Then you will find out it's exactly what you are looking for.
By default, an ImageButton looks like a regularButton, with the standard button background that changes color during different button states. The image on the surface of the button is defined either by the android:src attribute in the XML element or by thesetImageResource(int) method.
I can't imagine that such a complex layout is possible just using clean xml...
Hope it helps now!
I took a look at the preference activity that Android use for settings. i'm looking for something like UISwitch as shown in below image, does Android have one like this.
I can see the nearest control on Android preference settings is "list preference"
There is ToggleButton and CompoundButton (one extends the other).
But those have a different default display widget then what you are looking for. However either could be used along with your own drawable resources to create the "switch" type control that you are after.
But by default no the system does not include a widget that serves this function and looks the way you want it to.
No, In Android its called ToggleButton.
But still it can be developed by extending RadioButton placed in RadioGroup and giving its UI way you wanted.
In some apps I see an EditText widget combined with a Button on the right side (e.g. the search field in the twitter app).
How can I create a widget like that?
Regards,
Marco
I finally found a solution.
Here's how the google guys did it: search_bar.xml
Thanks for your help!
Check out the TableLayout and the RelativeLayout in the Android developer center.
There are a few more official tutorials on layouts here.
If you use the TableLayout, you can put an EditText in the left column of a two column layout, and then put the button on the right. Or, probably a better way, would be to use a RelativeLayout, which gives you a little more flexibility.
Take a look at Applying Styles and Themes and the Draw 9-patch tool. 9-patches are used as the background for widgets like EditText and Button. You can combine a custom widget background with padding and margins to get the effect you want.
I am trying to make a button programmable way (no attributes on LinearLayout).
In other words, button count on the View is dynamically.
How to make it ?
Thanks
Take a look at this article it demonstrates creation of Android UI in java code rather than using the declarative approach