Android styles.xml windowNoTitle (ActionBarActivity) - android

I want to hide the title bar (where the activity tile is shown) in my application. I'm doing this by setting the android:windowNoTitle item to true. This works fine for devices with API level 19. I tested it with a device running API level 10 and it only hides the notification bar. The tile bar is still shown.
Here is my res/values/styles.xml
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
EDIT: I'm using the AppBaseTheme as the theme in my manifest. There are no other styles.xml files in any other value-vXX folder.
Edit#2: I'm extending an ActionBarActivity for my activity.

try using this
<style name="MyMaterialDialog" parent="Base.Theme.AppCompat.Light.Dialog.MinWidth">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
remove android prefix!

I tried the android:style/Theme.NoTitleBar.Fullscreen in styles.xml but I got:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
So I followed the advise to stick to the AppCompat theme, and could hide statusbar and actionbar using the following lines in styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>

I use 1 theme for all the devices and it works perfectly on API level 8 to 16 (since I only have 5 physical devices). I'm sure it's working on 17-19 devices too.
Make sure that in your Manifest file (in the application section), there is a line like android:theme="#style/AppTheme"
Try using this for your theme:
<style
name="AppBaseTheme"
parent="android:style/Theme.NoTitleBar.Fullscreen"
>
<item name="android:windowNoTitle">true</item>
...
</style>
And remove the styles/themes in the values-xy folders
[EDIT]
Since the AppCompat theme is NOT full screen, by definition, the StatusBar will go away, but not the TitleBar
If you don't need the ActionBar offered by the AppCompat, then you should get rid of the AppCompat as soon as possible: don't bloat your apps with unneeded and unwanted things
For instance, I have a Header Bar and a Footer Bar, but these are simply RelativeLayouts I implemented my own.
And still have the freedom of using the whole screen surface.

Related

How to style Android's AppBar action text?

I need to change text size of action buttons in AppBar/Toolbar. It should be 14sp, but I'll use 20sp in this example, because it is more evident. I am using appcompat-v7 22.1.1
At first I tried to use theme attribute android:actionButtonStyle:
<style name="FirstAttemptTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionButtonStyle">#style/Custom.Widget.AppCompat.Light.ActionButton</item>
</style>
<style name="Custom.Widget.AppCompat.Light.ActionButton" parent="Widget.AppCompat.Light.ActionButton">
<item name="android:textSize">20sp</item>
</style>
Then I ran application on the Lollipop and the result was as needed:
But then I used an emulator with lower version and my theming had no effect:
I digged a little deeper and discovered that abc_action_menu_item_layout.xml is used for action menu items and it has a line android:textAppearance="?attr/actionMenuTextAppearance"
So I tried to modify this theme attribute (I also had to add textStyle:bold):
<style name="SecondAttemptTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionMenuTextAppearance">#style/Custom.TextAppearance.AppCompat.Widget.ActionBar.Menu</item>
</style>
<style name="Custom.TextAppearance.AppCompat.Widget.ActionBar.Menu" parent="TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
</style>
As in the first time, the result was as needed on Lollipop and no effect on any version below.
So, the question is: how to properly change text size for action menu item?
PS: I created a simple project on github to demostrate my issue
It appears that actionButtonStyle and actionMenuTextAppearance should be used without android: namespace.
As it can be seen in values-v21/values.xml of support library, Lollipop uses attribute from system theme (note the android: prefix), that's why my attempts worked with it:
<style name="Base.V21.Theme.AppCompat.Light" parent="Base.V7.Theme.AppCompat.Light">
...
<item name="actionButtonStyle">?android:attr/actionButtonStyle</item>
...
</style>

Android actionbar style ignored by later devices, using appcompat v7

I am using the Action Bar support library (appcompat v7), my app is set to a minimum api of 7, and a target of 21.
I have two styles files, a base one, and one targeted at devices api 11+.
When running the app on a device running KitKat, it seems that android:actionBarStyle is ignored, leaving the action bar styled as default (#style/Widget.AppCompat.ActionBar.Solid), instead of applying the given background.
But if I remove my v11 styles/comment them out, KitKat listens to the actionBarStyle attribute set in the base styles.xml file and sets my custom background without any problems.
So my question, where am I going wrong with the v11 styles?
From what I understand, according to the android docs, you are supposed to supply the additional styles for devices running 11+ using the android: prefix, but this just doesn't seem to be working for me.
Stripped down, this is my /res/values/styles.xml file:
<style name="My.Theme" parent="#style/Theme.AppCompat">
<item name="actionBarStyle">#style/ActionBar.Solid</item>
</style>
<style name="ActionBar.Solid" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="background">#drawable/ab_solid_</item>
</style>
and this is my /res/values-v11/styles.xml file:
<style name="My.Theme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/ActionBar.Solid</item>
</style>
<style name="ActionBar.Solid" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_</item>
</style>
as you can see, the only difference between the two is the use of the android: prefix.
According to the official doc, with the new AppCompat-v21, you can remove all of values-v14+ Action Bar styles and use only one theme declaration, in values:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s actionBarStyle -->
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>

ActionbarSherlock and homeAsUpIndicator

I have the problem to customize the back arrow. I want a red arrow instead of default arrow. I've read many topics about that but it doesn't work.
So i place my styles in res/values/styles.xml. Here is my code :
<style name="AppBaseTheme" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/Widget.AppTheme.ActionBar</item>
<item name="homeAsUpIndicator">#drawable/btn_nav_retour</item>
</style>
I can't set "android:homeAsUpIndicator" beacause it requires api level 11 and my min sdk is 9.
Should I set the same code in res/values-v11/styles.xml ?
Thx
To work in all API's you should create style.xml in values-v11 and values-v14 folder. In values-v14 for example you should use:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/Widget.AppTheme.ActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/btn_nav_retour</item>
</style>
In default values folder you should use attributes given by ActionBarSherlock, but for higher API levels you should stick with Android default ActionBar attributes and place android: in front of them. In that way it will work for higher API levels.
As a sidenote to the accepted answer:
if you don't want to duplicate your Theme for both API-ranges, you could add both items to your AppBaseTheme in values/styles.xml:
<style name="AppBaseTheme" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/Widget.AppTheme.ActionBar</item>
<item name="homeAsUpIndicator">#drawable/btn_nav_retour</item>
<item name="android:homeAsUpIndicator" tools:targetApi="11">#drawable/btn_nav_retour</item>
</style>
The targetApi-attribute prevents the error-message from lint. The xml-item it annotates is ignored by older Android-versions.

How can I have a drop shadow on my ActionBar (ActionBarSherlock)?

I am including my styled xml layout:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Styled" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/Widget.MyApp.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.MyApp.ActionBar</item>
</style>
<style name="Widget.MyApp.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
<item name="titleTextStyle">#style/Widget.MyApp.TitleTextStyle</item>
<item name="background">#color/red</item>
<item name="android:background">#color/red</item>
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Widget.MyApp.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">21sp</item>
</style>
</resources>
Some of the search over internet suggests that use windowContentOverlay set to #null. But when i use it in the style xml it doesn't change anything. Can any one help what to do?
If you want to create a shadow below the ActionBar you have to set android:windowContentOverlay parameter on the application theme (in your code you are incorrectly setting it on the ActionBar style).
In your example it would be:
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="android:windowContentOverlay">#drawable/my_actionbar_shadow</item>
</style>
Using #null value removes the shadow.
This one line sets the shadow on ActionBar on Android 3.0 and newer. However if you are using ActionBarSherlock, it will not work as you expect. It would create the shadow on top of the window over the ActionBarSherlock on Android devices running system older than Android 4.0 (although ActionBar is present in the api since Android 3.0, ActionBarSherlock uses custom implementation for all Android versions older than Android 4.0).
To create the shadow below ActionBarSherlock you have to set windowContentOverlay parameter on the application theme (notice the missing android:).
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="windowContentOverlay">#drawable/my_actionbar_shadow</item>
</style>
Again, using #null removes the shadow.
Although this line works for ActionBarSherlock, it doesn't work on android devices running Android 4.0 and newer, no shadow is created under the ActionBar on such devices. So how to combine these two parameters to get the desired shadow under both ActionBar and ActionBarSherlock?
Use resource configuration qualifiers, in your case use platform version qualifiers.
In res/values/styles.xml use the second xml code. And in res/values-v14/styles.xml use the first xml code. Therefore the ActionBarSherlock version is used by default (for versions pre Android 4.0) and ActionBar version is used for Android 4.0 and newer.
Edit:
There is a bug in Android 4.3 (API level 18), android:windowContentOverlay does not work. It should be fixed in future release. In case you need it fixed in Android 4.3, you can find workarounds linked in the bug report.
As a previous answer did say use "windowContentOverlay" in the application theme and NOT the action bar style.
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="windowContentOverlay">#drawable/my_actionbar_shadow</item>
</style>
If you want a realistic shadow you can find one in the
"Your Android Folder"/platforms/android-16/data/res/drawable-hdpi/
ab_solid_shadow_holo.9.png and copy it to your drawable-hdpi folder then the end result is
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="windowContentOverlay">#drawable/ab_solid_shadow_holo</item>
</style>
In addition, above API21(Lollipop), you will need this in code, too.
getSupportActionBar().setElevation(0);

Android: ActionBar Hidden

I have an old app which now when run on tablets like the Xoom, hides the ActionBar. The app was written before the ActionBar existed so some old code is hiding the actionbar.
What in an old app can hide the ActionBar? I need to change it so that the ActionBar and therefore the menu can be shown:
Here's my very simple Theme:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Black">
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#android:color/transparent</item>
</style>
<style name="TextViewStyled" parent="#android:style/Widget.TextView">
<item name="android:textStyle">normal</item>
<item name="android:lineSpacingMultiplier">1.22</item>
</style>
</resources>
And here's the only window settings I use:
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_RIGHT_ICON);
Using android:Theme.Black as your theme parent is what's "hiding" the action bar. The Holo and DeviceDefault theme families include an action bar by default, but the legacy theme family (from which Theme.Black derives) does not.
Use a theme declared with the same name "MyTheme" in res/values-v11/themes.xml with a parent of #android:style/Theme.Holo. This version of the theme will be used on devices running API level 11 (Android 3.0, where Holo and the action bar were introduced) or newer. You should similarly use Widget.Holo.TextView instead of Widget.TextView when declaring a custom view style to work within the Holo theme.

Categories

Resources