My new game app was originally designed for a targetSDK of 13. I've since bumped it up, but my default buttons have changed in appearance. Not on the emulator, but on my actual Galaxy S3 phone, running 4.0.4.
The old buttons were rectangular with a translucent background and white letters. The new buttons look the same, but have an opaque, dark gray background. It happens for any targetSDK greater than 13.
Any ideas why, and how I can fix it? I'm not applying any specific style to them.
It is happening because of googles new holo theme
The way to stop it from happening is to specifiy a theme in you manifest (right below the android:name and android:label attributes of your activity. Adding the following line will remove you
<application android:theme="#android:style/Theme">
This should remove the holo theme, if it doesn't you can play around with some other themes until you find one which works. This might help - http://developer.android.com/guide/topics/ui/themes.html
Related
I am using Android Studio 2.2.1 with project with these settings:
compileSdkVersion 24
buildToolsVersion "24.0.2"
minSdkVersion 16
targetSdkVersion 24
If I use the GUI to change the button background, it adds this to the layout:
android:background="#color/colorPrimary"
Then, if I run the app on a 4.4 virtual device (Microsoft's Android Emulator because I'm on an AMD system and I want a fast emulator), or on a Samsung Galaxy S6 with Android 6.0.1, the button has the correct color but loses left and right padding and the text runs right to the left and right edge of the button.
If I set only the backgroundTint, then the button has the correct padding on the virtual device, but not the correct color. However, on the S6, it has the correct color and padding.
This seems like a bug somewhere, but where? Is it in the code generation or is this a bug in Android 4.4?
I think Android Studio should be doing whatever needed to make it work correct on both platform levels, whether it is as complex as some of these solutions:
Standard Android Button with a different color
or something more succinct.
My styles.xml file shows:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
and my AndroidManifest theme setting is:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
This seems like a bug somewhere, but where?
Right here:
android:background="#color/colorPrimary"
Is it in the code generation or is this a bug in Android 4.4?
No, it is your replacement background. It is a color, without any intrinsic padding, and without being wrapped in a StateListDrawable.
The stock background of Button widgets has some amount of padding enforced as part of the background itself (e.g., via some transparent pixels in the nine-patch PNG used for the background). The actual background itself is a StateListDrawable, which chooses one of several other drawable resources to apply based on the state of the Button (e.g., normal, pressed, focused, disabled).
To replace a Button background, you need to first use a StateListDrawable of your own. Otherwise, your Button will not appear to respond visually to click events or other state changes (e.g., being disabled). Then, you can either incorporate some padding into the backgrounds for your states, or put padding on the Button widget itself, as you see fit.
I think Android Studio should be doing whatever needed to make it work correct on both platform levels
Android Studio assumes that you know what you are doing. There is no hard-and-fast requirement that Button backgrounds have this sort of padding, and there is no hard-and-fast requirement that a Button be something that makes sense to users (versus "hey, why does this button seem to not respond visually when I tap on it?"). There will be scenarios where developers do want Button widgets to have no padding, such as in an implementation of a segmented-list-control sort of compound widget.
Personally, I think the decision to have some intrinsic padding in the Button background is regrettable. But, that's the way it was implemented back in Android 1.0, and Google has elected to maintain the approach, even with newer themes, presumably for backwards compatibility.
If I set only the backgroundTint, then the button has the correct padding on the virtual device, but not the correct color
I have not played with backgroundTint with appcompat-v7. It is possible that you are seeing a bug there. You might consider posting a separate question with a complete example, plus screenshots, to get more specific help with that particular concern.
I am in a fairly serious predicament. I have built my entire app using ?attr/colorPrimary to pick the color for background shapes, as I have devised a way to dynamically change the theme and color. This works perfectly on 5.0, but on all 4.x devices, ?attr/colorPrimary crashes the app. Why does Android studio not alert developers to this incompatibility?
Is there a support version of ?attr/colorPrimary?
colorPrimary is already part of AppCompat as of version 21 and works back to API 7. Your problem is instead with your theming code.
I believe it was added after Android Lollipop - API 21.
At least this link shows that it was added between API 20 and 21:
https://developer.android.com/sdk/api_diff/21/changes/android.R.attr.html
attr/colorPrimary just point to colorPrimary defined in current theme.
I'm not sure how you implemented your theme.. But you can create your own attr... This option is good only if you support several themes.
If you have a single theme, I believe you can replace it by a color.
API 21:
Material design style
Notifications are drawn with dark text atop white (or very light)
backgrounds to match the new material design widgets. Make sure that
all your notifications look right with the new color scheme. If your
notifications look wrong, fix them:
Use setColor() to set an accent color in a circle behind your icon
image. Update or remove assets that involve color. The system ignores
all non-alpha channels in action icons and in the main notification
icon. You should assume that these icons will be alpha-only. The
system draws notification icons in white and action icons in dark
gray.
The problem is a glitch in Android code. See this, it is not the exact same but the reason is.
In case anyone out there has this problem, I want to explain my workaround.
Remove all instances of "?attr/color(Primary, Dark, or Accent)" and attempt to mimic the effect in each individual element in each individual activity. This is not a full work around, but for me it works. Google really needs to resolve this issue. If you know a better work around, please let me know and I will accept it as the better answer as long as it works.
In styles.xml inside of values/, values-v11/, and values-v14/, ive set the AppBaseTheme to android:Theme.Holo.
Now it seems to work well, except it is not showing the nice background gradient when I run it on a 4.2 AVD with API level 17.
I saw something along the lines of hardware acceleration. Could this be why it isn't showing the background gradient that the Holo theme should use? Is it something in the settings within the AVD? Or am I missing something else?
How do I get the Holo background gradient to show in my app when I run it on the AVD? I know this is purely cosmetic, but I think it looks nicer and I want my app to utilize it.
I have a custom notification that uses a LinearLayout that contains an ImageView and a TextView. Before Android 4.0 all I needed to do was swap out the text colors with the EventContent and EventContent.Title styles and all the colors looked great.
But on Android 4.0 (Ice Cream Sandwich) my custom notification background color is a light gray, and to make matters worse it clashes horribly with the default text styles. This is strange to me, since all the other notifications have a dark-gray (almost black) color, and I haven't changed the background color at all in my layout.
Is there a way to access the default background color for notifications? I don't want to manually set this to black (or another color) since I want it to go well with the theme on the device. But I've looked around and can't find anything that gives me that color.
I also have a custom notification and found that the background color was also gray on ice cream sandwich. I see this with other apps too, like WeatherBug.
I had no targetSdkVersion in my manifest. I found that by adding targetSdkVersion="14" to the manifest the problem is fixed. The background is now the appropriate color for each android version.
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="14" />
Edit: Google confirms this is the correct approach. See #16 at https://code.google.com/p/android/issues/detail?id=23863&thanks=23863&ts=1325611036
This appears to be a bug in Android 4.0.3. See bug report for updates: http://code.google.com/p/android/issues/detail?id=23863&thanks=23863&ts=1325611036
In my application, I use some dialogs to display information.
The theme of my application is Theme.Light since 2 years, and these dialogs have always been black since the beginning.
Now with ICS, it seems that Google just changed his mind and turned these dialogs into white:
See the screenshot of my Moto Xoom and my Galaxy Nexus:
What is the best practice to handle that true fragmentation?
I have been thinking about creating different layout: layout-v14 but I will soon become crazy, if I have to create layout-v15,v-16, etc for the future?
Or is there a way to tell "lower than v14" and "higher than v14"?
layout-v14 apply to v14 and higher, so if any different style will appear in future you able to add layout-vXX to support this. And all versions between v14 and vXX will apply v14 layout.