Android: Different widget layouts for Honeycomb/Gingerbread - android

I'm working a personal project that's going to include a home-screen widget updated with information from a service - I'm developing using a Android 3.1 tablet (physical) as well as an Android 2.3 emulated phone.
For the Honeycomb version, I'd like to use the StackView, building up 3-4 pages which the user can swipe through, whereas this isn't supported on pre-Honeycomb devices, so is there an easy way to
have Honeycomb devices use a StackView but have Gingerbread/earlier use a TextView (I think this can be done by using res/layouts-v1{1,2,3,4}
Have the RemoteView detect which it is and clear/create the StackView items or set the text on the TextView

You can indicate different layout for pre and post Honeycomb by using the v11 qualifier in your layout names. You can also use the Build class to detect what Build version you're running on and then load the appropriate layout.

Related

Make Android Studio apps available for all devices

I have a question about Android Studio.
If I develop an app that I then upload to the Google Play Store, can I be sure that my Android Studio project runs well and looks good on all devices with an Android operating system?
So that the layout that I developed works well on all screen sizes? Will Android Studio do this for me on its own?
Or do you have to develop your XML layout for each individual smartphone with different screen sizes?
I would be very happy to hear from you.
best regards
However, applications created in android studio will be able to fit all api's that you define in your gradle, it is recommended to test in the emulator from the initial api defined in the gradle, but in general it works well on several devices. The test is ideal to check if there will be no crash in some API's but the layout is usually positioned according to the screen of each device.
Good luck on your project.
So that the layout that I developed works well on all screen sizes
For this, it depends on how you did your layout. Android has constraint layout which is the best to use
ConstraintLayout is a layout on Android that gives you adaptable and flexible ways to create views for your apps. ConstraintLayout , which is now the default layout in Android Studio, gives you many ways to place objects. You can constrain them to their container, to each other or to guidelines.
Or do you have to develop your XML layout for each individual smartphone with different screen sizes
For this, it will only base on your use case or if you have different UI design for phone and tablet devices, for example, you want your app to show a two-pane layout on a larger screen (or a tablet), then you have to create a new xml for this. So you'll have mylayout.xml placed in layout folder (for phone device screen sizes) and mylaout.xml placed on layout-600sd600dp (for tablet device screen sizes).
But if you only have on design for both phone and tablet devices, then you only need one xml layout.

I wanna create selector for Switch on both Android 5.0 and less android 5.0 application

I wanna create theme for both Android 5.0 and less android 5.0 application.
In first case for example I have Switch that if I don't set any background it appearance will change on Android 5.0 to like a slide button as you know,
but in less android 5.0 it show as on/off button.
when I put
android:thumb="#drawable/switch_selector"
to change thumb image and color it's fine on android 4.4 but my Switch show nothing on Android 5.0. my question is how to create a selector or theme for Switch that can show on all devices?
UPDATED
in simple way, we hava many drawable folders for each screen dpi's. I wanna know if I can set drawable for each Api's as like as for each dpi's ?!
after my hard times with Android notifications, where I need to do one method for android devices with Android 5.x and higher and another method for pre-Lollipop devices, I would advice you to search for additional libraries like this
SwitchButton
This project provides you a convenient way to use and customise a SwitchButton widget in Android. With just resources changed and attrs set, you can create a lifelike SwitchButton of Android 5.0+, iOS, MIUI, or Flyme and so on.
Now we get the biggest movement since SwitchButton published. v1.3.0 comes with totally reconsitution and more convenient API. A wholly new demo can give you a tour in it.
Github page: https://github.com/kyleduo/SwitchButton
More like this you would find here: http://android-arsenal.com/
Additional libraries may help you to avoid problems with backward compatibilities of Android components.
Like you said, you add this line of code:
android:thumb="#drawable/switch_selector"
and it works on Kitkat, but not on Lollipop.
I've found already that on Lollipop you may have much more to work.
Just take a look here: How to have a Lollipop switch button
So try to find your desired additional library like this above and let me know how it works ;-)
EDIT: To get API version use this:
Build.VERSION.RELEASE;
That will give you the actual numbers of your version; aka 2.3.3 or
2.2. The problem with using Build.VERSION.SDK_INT is if you have a rooted phone or custom rom, you could have a none standard OS (aka my
android is running 2.3.5) and that will return a null when using
Build.VERSION.SDK_INT so Build.VERSION.RELEASE will work no matter
what!
To use it, you could just do this;
String androidOS = Build.VERSION.RELEASE;
From: Retrieving Android API version programmatically

Are all layout elements that are available on Android Phones available on Android Wear?

Android Wear Watches are a lot smaller then Android phones, but when looking over the Android API pages and training guides, I didn't see any restrictions on layout elements. Some layouts, however, wouldn't make sense on some watches. For example, a large custom layout ListView wouldn't fit very well on round watches. Are all layout elements really available on Android Wear?
Not all layouts are available (WebView for example). You can see the unsupported libraries here.
And some layouts are meant to be used in Android Wear only.
There is no restriction as far as I know. There are some adjustments that one need to pay attention to in order to have a pleasant UI on both square and round displays, by adjusting the location of items and taking advantage of what the platform adds for handling round vs square, etc but outside of that, all the layouts are, as far as I know, available there too.

Android widget vertical scroll for Android 2.3.6

I'm trying to figure out how to enable vertical scroll for an Android widget.
From what I read in the documentation and this post it's possible to do that only from Android version 3.0 and up.
However, I saw a phone (Motorola Razr) with Android version 2.3.6 that had a Gmail widget with a vertical scroll.
So I can't understand if it's possible or not? And if it is possible, how to implement it?
Manufacturers generally build out Android from a custom version of AOSP. Since the entire source for Android 2.3.x is available, it is quite possible that Motorola simply added support for scrolling widgets by modifying the source for their own devices (potentially using the same techniques that AOSP 3.0 does). And if this is indeed the case, that will require changes in the underlying operating system and hence will likely not be available to you if you are building the widgets using the SDK.
If by widgets you are talking about ? extends widget.View, you can always build you own View that does vertical scrolling.
This envolves parsing onTouchEvent (and probably onDispatchTouchEvent) and a lot of math.
I did it myself at work.

Simulate stack view in Android 2 (API 5)?

My App must have a widget that can show cards and user can turn over cards. StackWidget sample (in Android's resources) has a good widget:
But there is a StackView in layout of widget and it is available since API Level 11 and I have to implement my App for API level 5.
Also I saw this widget that works API level 7 and upper, and I guess uses OpenGL ES:
Finally how we can simulate stack view in Android 2 (API 5)? Or how we can implement a widget like second image (above)?
It is absolutely impossible to use custom views in widgets because of security. You can only use system ones marked with a #RemoteView annotation.
Those fancy animated scrollable 3D widgets OEMs used to put in their firmwares only work with their custom launchers because they are aware of those custom views and allow them to be inflated. Alternatively, these widgets can as well be a part of said custom launchers.

Categories

Resources