I'm working on an application for Honeycomb and have tried out various themes for it, including the default Holo theme, Holo Light and Holo Wallpaper. My layout is using a HorizontalScrollView with ImageViews and I've found that it gets a bit laggy when using the default Holo and Holo Light themes. It's super fluid with the Holo Wallpaper theme, though, despite it including a bitmap background.
I've even tried making my own theme with a bitmap background, but that just slows down everything even more.
I'd like to have a speedy ScrollView, so if anyone has an answer to why some are faster than others, please let us know :-)
It sounds like you are drawing too many layers. The Holo theme, especially when hardware accelerated, has a default background image on the window. Try to remove it if it's not visible.
I feel like such a noob. Here's how to enable hardware acceleration in Honeycomb. Add this to your manifest file in the application tag:
android:hardwareAccelerated="true"
Related
I've been experiencing an issue with creating an icon that fits in any size and shape. I use Studio to do it, but I must be doing something wrong, because there is a small padding in it.
I add my image asset as background layer with nothing in foreground layer.
I've tried to fix it by trimming it and using huge icon source 1920*1280.
When I changed to new theme it turned out that few other apps on my phone(other devs) have same poor icons.
Also tried this
Creating an icon using foreground layer totally solves this issue.
The number pickers in Android contain a shadow above the previous and next value(s). Is there a attribute to make this shadow transparent?
If an image is being used as the background, these shadows are distracting.
Edit:
Running emulator with Android version 6.0.
Setting the solidColor attribute makes the shadows appear in different colors. Unfortunately, setting it to transparent still keeps the black fading appearance.
How this renders during emulation with the background image:
I think it's just the Android version is too old. I didn't do any customization to numberpicker and it still looks flat (no ugly shadow like that). My test device running 6.0
I've gone through almost all of the android developers page, as well as stackoverflow, but cannot seem to find a straightforward answer. My app uses the default holo.light theme, and all I want to add is a simple line dividing the app about 2/3 of the way down. I still want to keep the holo theme though. Just a line across the middle. Do I have to make the image myself, or can I do that right in the xml? Doing it right in the xml would be a lot easier in my opinion.
I still want to keep the holo theme though
A dividing line would have nothing to do with the theme.
Do I have to make the image myself
Well, the line has to come from somewhere. That could be a nine-patch PNG file in an ImageView, or a background color on a View, or a ShapeDrawable background on a View, etc. Only you know what you want your line to look like.
can I do that right in the xml?
You can define the View or ImageView in your layout XML. If you choose to create a nine-patch PNG file to serve as the image, that you would have to create yourself, using a combination of a graphics editor and the draw9patch utility.
Different Android devices have different themes.
That means, that background colors, like in dialogs, may differ among Android versions and among manufacturers.
This may result into icons getting "invisible":
The problem with stock Android themes could be solved relatively easy, by providing different colored icons in target specific folders, e.g. white icons in a folder drawable-v14, and black ones in drawable-v10.
But that does not solve the issue that comes with customized themes from manufacturers, may it be TouchWiz, Blur or Sense.
It is simply not possible to cover every device by this method.
Another way would be, to draw a small black border around white icons, and vice versa.
But if the background would be gray, like in ICS, it wouldn't look good, either.
So, the question is: How to provide custom icons, that will work well on every theme, without touching the theme itself?
Accounting for all vendor choices (and mistakes) would be a pain.
I see a couple of options:
Explicitly select a stock theme and hope for the best
Select a custom theme derived from a stock theme, where you control the background color
Dynamically evaluate the background color for the chosen theme, and set the icon based by a tipping point (e.g. dark icons if background is light enough). Not sure if this would be practical, but at least it should be somewhat universal.
I recently went with the hard-coded colors in a derivative theme to fix a bug in the Nook dialog color selections for a dialog. More extensive testing would probably show me another platform that I just made worse with that.
Hopefully someone has a better answer than those, because none of those seem completely clean and universal. Reading your post again, it looks like none of those options meet your criteria of not touching the theme, either.
I have realized that there are at least two background colors on Option menu of Android. On the HTC Hero, the background is white and on Samsung Galaxy S II, the background is black.
This became a problem when I set the icons for the background menus. Is there some way to detect the background color of the Option menus in Android?
Possible solutions:
Don't use icons.
Design icons according to the guidelines - http://developer.android.com/guide/practices/ui_guidelines/icon_design_menu.html. There are three different guidelines for up to 2.2 (white background), 2.3 (black background) and 3.0+, so it's a lot of work...
As Profete162 suggested, use #android:drawable/ic_menu_*
For Android 4.0+, you can also set the light / dark Holo theme, which is guaranteed (at least in theory) to remain unchanged across different phone manufacturers - so it'll look the same in HTC Sense, Samsung TouchWiz etc.
That's indeed a very annoying issue.
On my implementation, I always try to use standards icons from android.R.drawable.IC_menu_*, so I am sure these icons are part of the framework and users are always positively surprised to see their generic icons in my app!
That gives a really good continuity in the user experience on the device, but that doesn't answer your question, but at least provide a workaround.
Here are for instance all android 2.2 icons: http://androiddrawableexplorer.appspot.com/
You can trust me, using these icons will always fit your colors.
First of all to answer your title question:
You can reference and read the background of the options menu by reading the attributes of the current theme. The attribute for this is panelFullBackground. E.g. set it as the background of a textview in XML¹:
<TextView android:background="?android:attr/panelFullBackground"
... />
Note that the background seems to be a solid color, but it's not - it's actually a bitmap. If you look closely you can see a grey border at the top (android 2.3+), or a drop shadow (<= android 2.2), so its'a bit difficult. Luckily there is a different attribute called panelColorBackground which matches the background color of the drawable as close as possible. So if you want just the normal background color, use this instead.
¹ This can surely also be read from code, but I don't know how from the top of my head at the moment, maybe I'll look it up and edit it in later.
Regarding icons
So you have the color as stated above, but you still have to process it to know if it's a dark or a bright color. You can do that, but that's not the usual way to deal with these icons and probably a good bit of work until you cover all the possible cases - not to mention that you have to create icons for each variant.
Normally you should adopt the platform menu icon style. This works across all devices and looks familiar to your users (custom icons that dont follow this often look "wrong" - e.g. astro file manager does this I believe).
You can do that by hand (see the guidelines), but the way better alternative is the Android Asset Studio.
It comes in two flavors:
As a webapp
Integrated in the latest version of the ADT plugin for eclipse
(under File->New->Other->Android Icon Set)
The workflow for both is pretty similar, select the point "Menu Icon" and follow the wizard. It will promt you to enter a simple, black and white bitmap of your desired icon that just outlines it's shape. After you specified one, the asset studio will generate everything for you. Play a bit around with the "clipart" option, that has a few example bitmaps ready to see how it works. When finished, the webapp gives you a simple zip which can be extracted into your project directory, the eclipse version adds it directly to the project that you select in the wizard.
The background color can be anything, because its implemented in Framework by manufacturer. You can't read it, in fact you will never need to read it.
Just create your custom menu layout in res/menu folder, set style and use it.