I'm using ActionBarSherlock on my app and when I disable some MenuItem in the ActionBar the icon turns translucent on my phone (HTC One X running stock Android 4.0.4) but I haven't seen this behavior in any other phone or emulator.
Am I right in assuming this behavior is not the default one for the native ActionBar? I like the idea though... It warns the user that the MenuItem is not enabled for some reason (in my case, it's a save button and if at least one field is not filled, it disables the button).
I was thinking in providing myself a translucent icon and set it manually when the MenuItem is disabled. This will work on every Android version, native ActionBar or not. The problem is that on my phone (or any other with the same behavior for that matter), it will be twice as translucent and I don't want that.
Any ideas on how can I properly achieve this effect?
I think that the problem is on the Theme, you are applying the default theme. So, HTC override default theme resources, i think you have to create a custom theme and change the item_background to the default one on sdk resources.
<item name="selectableItemBackground">#android:drawable/item_background</item>
you would have to set the background to be independent of the theme. In the .xml file you could set :
android:background="?android:attr/listSelector"
on the view where you want the color.
Related
I am using the theme Theme.MaterialComponents.DayNight.NoActionBar (docs) for my Android app.
I am also calling getActionBar().hide() in the MainActivity.
On nearly all my devices, the Action Bar is not displaying. However on one device, a Pixel 6 running Android 12, I still see the Action Bar. I am sure I've installed the latest version of my app.
Any ideas why the Action Bar is still hanging around on this one device?
I had the same problem (I thought) until I realized that I had set the .NoActionBar style in my values/themes.xml but NOT in my values-night/themes.xml and the device with the "issue" was in dark mode.
Solution:
Set Theme.MaterialComponents.DayNight.NoActionBar in both values/themes.xml and values-night/themes.xml.
I'm developing a program, but as I have the mobile phone in the dark theme, some textViews have a white letter and don't appear due to the color that is placed on them.
But when I switch the phone to the lightweight theme, the textView all appear.
I would like to know if it is possible to disable the dark theme in Android Studio and only use the light theme, even when the phone is set to a dark theme.
Light Theme
Dark Theme
Just put this line in the launcher activity before setContentView()
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
This is a kind of short term solution if you don't want to properly implement dark theme in your app (the one that comes to the entire OS after A10)
Set your android:textColor=#android:attr/textColorPrimary which automatically choose the text color based on light or dark theme
Also, since you asked what to do to prevent from that default behaviour that switches your app to the dark mode when A10 and above devices turn on system wide dark mode then
You can make your Activity theme a descendant of Theme.MaterialComponents.Light or similar AppCompat variant . Currently all apps use Theme.MaterialComponents.DayNight which gives the default behaviour as above
If you decide to implement a system wide dark mode for your app, it's fairly easy, you can read about it here. Most of the widgets already come with dark mode support, it's just that you will have to do it for your own backgrounds etc
In your themes.xml your application theme's parent should be Theme.MaterialComponents.Light.NoActionBar, or if you wan't to use the action bar (you shouldn't), then Theme.MaterialComponents.Light.DarkActionBar
Actually I am using
#android:style/Theme.Holo.Wallpaper.NoTitleBar
in my android launcher app. But the problem is when I am changing
navigation bar color
for lollipop and above devices, it's not changing. I tried pro-grammatically as well as from styles.xml.
If I am using appcompat theme, then it's working. But I don't wanna use appcompat theme for my launcher app. So what is the reason behind it and give me solution as well.
When creating custom ActionBar icons what happens if the user changes their theme to something that makes your icon unreadable? Do they have this kind of power?
Example: So say I make an icon for my ActionBar in Holo Dark, so that the icon will be a lighter shade of white. What if the user changes their theme to Holo Light (or can they in my app?), forcing my icon to not be readable because it is also close to the same color as its background? I'm just concerned that if I create a custom app it will not look proper to only certain people.
I have been trying to find something about this but my searches and Google's Iconography pages didn't really give me a clear answer.
Android allows setting a themes to application/activity in AndroidManifest.xml, and you can change theme theme dynamically. If a user change their system themes, it don't affect you application. If you want to change your application/activity themes, you should call setTheme() before setContentView() in Activity.onCreate()
I have a non-market app that was built to run on a specific device. Originally, this was on a device running 2.2, but now the app is targeting a specific device on 3.1 and I am adding in support for the Action Bar.
One of the apps Activities is required to be full-screen and have hidden the status bar and the Action Bar. This is achieved using the following in the manifest:
<activity
android:name=".activity.EditorActivity"
android:label="#string/activity_edit"
android:theme="#style/Canvas">
Which references this style:
<style name="Canvas" parent="#android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#color/bg_white</item>
</style>
So, after moving to 3.1, the effect works, in that the Activity is fullscreen, and everything is hidden as needed, but this of course hides the options menu from populating the Action Bar.
I know that if I leave the android:targetSdkVersion="8", the options menu is shown in the bottom navigation, but this seems like a bit of a hack - is there any other way or 'best practice' for this? I basically have to set android:targetSdkVersion="12" to ensure the app works and isn't put onto older devices so this won't be a permanent solution.
I've decided to stop trying to swim upstream and have switched to using a translucent Action Bar that is overlaid - it works perfectly and is exactly what I had been doing prior to 3.x with my custom solution.
Custom Translucent Android ActionBar