I have an app for Android where in one screen, we have ToggleButton for 2.x and Switches for 4.x. I was able to create the layout folders for versions layout-v14 etc. and the layout xml's work fine.
My concern is from the coding standpoint, I want to be able to get the component (switch or togglebutton) from code and have it work from API 10 and later. However, the older API's do not have android.widget.switch. Is there any other work around? Otherwise I'll have to show a ToggleButton to all users :(
I treid to read the below for this:
http://www.edumobile.org/android/android-tutorial/switches-example-in-android/
http://developer.android.com/guide/topics/ui/controls/togglebutton.html
I figured it out. They both inherit from CompoundButton. So it's ok to import android.widget.CompoundButton. No need to import ToggleButton or Switch. Case closed.
Related
i am trying to make a alarm clock, the GlowPadView in the newer android versions it quite good looking and i was planning to use that in my application, but at the same time i also want to support 2.3.3(Gingerbread) which still has a major chunk of phones. So i was wondering if there is a way that i can check the android version the phone is running and show the layout according to that. If the phone is running API 11 + the layout shows GlowPadView otherwise it shows basic swipe views from the Gingerbread stock alarm application.
To check the android version Build.VERSION_CODES can be used
android.os.Build.VERSION.SDK_INT;
So i was wondering if there is a way that i can check the android version the phone is running and show the layout according to that.
Create separate directories, such as res/layout/ and res/layout-v11/. Have the same-named layout resource in each (e.g., foo.xml), and put the GlowPadView in the foo.xml that you place in res/layout-v11/.
As you stated, you could just create two completely separate layouts, and then have an if (android.os.Build.VERSION.SDK_INT > 11), setContentView() to one layout and if (android.os.Build.VERSION.SDK_INT<=11) setContentView() to a different layout.
I want to use the Switch toggle button (on/off) of Android 4.0 in Android 3.0. I would like to know there is any supported library for it. I have tried to copy the source code of android.widget.Switch from ICS, with no avail.
Thanks.
A quick google search revealed this two libraries:
https://github.com/ankri/SwitchCompatLibrary
https://github.com/BoD/android-switch-backport
I have no experience using either of them, but the latter one seems to have a sample on the Play store with the following screenshot (image taken from the app's page):
I spend an unpleasant time looking for erros in my android layout, fields not showing up being the predominant one. As I see other people here also struggling a lot with android layouts I thought to throw this question in even so not completely according to the SO question guidelines.
What tools are out there to help with the creation of android layouts.
there is only one i know. its called http://www.droiddraw.org/
over the time i figured though that the best is still to create your own by code.
If you're using a newer SDK within Eclipse (eg android 4.0 or 4.1) it should help you with the layout (with much more functional drag and drop and alignment/spacing). However, you may still want to manually verify it to make sure it's exactly what you want, since you'll be changing other parameters too.
My friend tried my app with his new galaxy tab and it seems it is a little different than the emulator I tested it on. His options menu for the app was dark instead of the white background and you could not really see any of the options and most of the app did not work properly. I made the app on the 2.1 android update and am very stumped I tried searching for something about this but could not find anything. Is there a way to modify to act accordingly if this happens?
Samsung modified a lot of standard themes and images. The only way to fix it, that I found, was to force my own theme and use my own images everywhere.
Since Android 2.3 the menu background has changed to black. But the general color palette for the icons you make shouldn't be that much different. See more here:
Android Menu Design Guidelines
If you wish to have different icons for android version 2.3 and earlier versions put the icons for Android 2.3 and later in a resource folder with -v9 appended to the folder name. Example:
drawable-hdpi-v9
You should do the same thing with notification icons, as android 2.3 really made a big change to the way notification icons should look.
Btw, if you are looking for an easy way to make icons for your application, Roman Nurik's asset studio is really great: http://android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html
I've written a relatively simple app, and I've been testing it out on the various different API levels created through the SDK and AVD manager in Eclipse. It works great in all API levels except for level 3. I have a few spinners on the front page which work just fine, but my four buttons don't seem to be working. I've tried adding a breakpoint in one of the 'onClick' methods that I specified in my xml layout file, but the breakpoint never seems to get reached. I'm kind of at a loss here. Does anyone have any idea what could be going on here?
Level 3 does not support the onClick attribute in XML. Unfortunately, you'll have to wire up OnClickListeners in code.
... or drop support for 1.5. It's a small and shrinking part of the market.