I'm trying to show a logo in my action bar that is different from my app icon in an app that needs to be compatible with 2.3 (Gingerbread). Right now I have,
android:icon="#drawable/icon"
android:logo="#drawable/logo"
in my manifest file which correctly shows on 4.0 and above devices. However, all of the action bars on 2.3 devices show the icon instead of the logo. The following code in onCreate in an activity works on 2.3 devices:
getSupportActionBar().setLogo(getResources().getDrawable(R.drawable.logo));
But, I'd like to avoid having to set this separately in each of my activities. Is there a way to set this in xml, in the manifest or theme perhaps? I've also tried
<item name="android:icon">#drawable/logo_listy</item>
in my theme actionBarStyle.
You can specify android:icon for each activity in the AndroidManifest.xml.
I'm using Google's ActionBarCompat for this; if you're using ActionBarSherlock the same thing might work, but I haven't tried it.
You can set a logo in the style you have applied to the action bar in your app's theme. For example:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle" tools:targetApi="11">#style/AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar"
parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- this can be set in the manifest or here, and will set the logo for -->
<!-- devices with API level >= 11 -->
<item name="android:logo" tools:targetApi="11">#drawable/logo</item>
<!-- this will set the logo for devices with API level < 11 -->
<item name="logo">#drawable/logo</item>
</style>
Related
How can I do the same animation that Google Chrome on Android and Google Play have. The effect that I want is when I scroll the Action Bar disappears but smoothly, how can I do that?
Example: (sorry but I can't upload videos here)
https://drive.google.com/open?id=0B7otV-_1sdEvaGFVbzY5cy0wX1VpNEJzNzQ3bXhDTXljR1d3&authuser=0
There is official documentation on how to achieve this effect: https://developer.android.com/training/basics/actionbar/overlaying.html.
To enable overlay mode for the action bar, you need to create a custom theme that extends an existing action bar theme and set the android:windowActionBarOverlay property to true.
Enable Overlay Mode
For Android 3.0 and higher only
If your minSdkVersion is set to 11 or higher, your custom theme should use Theme.Holo theme (or one of its descendants) as your parent theme. For example:
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
For Android 2.1 and higher
If your app is using the Support Library for compatibility on devices running versions lower than Android 3.0, your custom theme should use Theme.AppCompat theme (or one of its descendants) as your parent theme. For example:
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.AppCompat">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
</resources>
Specify Layout Top-margin
When the action bar is in overlay mode, it might obscure some of your layout that should remain visible. To ensure that such items remain below the action bar at all times, add either margin or padding to the top of the view(s) using the height specified by actionBarSize. For example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize">
...
</RelativeLayout>
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>
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.
I am making an android app and using android-support-v7-appcompat to make sure my app support action bars from android version 2.2 and up.
I need to make the Action Bar overlay and use a translucent background so I have modified the styles.xml to this code :
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- TRANSLUCENT THEME -->
<style name="TranslucentAB" parent="Theme.AppCompat.Light">
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/BlackBar</item>
<item name="actionBarStyle">#style/BlackBar</item>
</style>
<!-- TRANSLLUCENT COLOR STYLE -->
<style name="BlackBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/halfblack</item>
<item name="background">#drawable/halfblack</item>
</style>
</resources>
and modified manifest file to adapt the new ActionBar as :
android:theme="#style/TranslucentAB"
The problem is that the following two lines of code require API level 11 and up :
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/BlackBar</item>
but I need to support from API level 8 and up. If I remove these two lines the app runs fine on Android 2.2 with black translucent action bar. But if I run the app in Android 4.3 the app launches with a solid white action bar. halfblack is just a png file in drawable folder with 70% black color.
Found solution to my problem :
I have to make separate styles.xml in res/values-v11 to support the same functionality in android 3.0 and up
To use the action bar overlay with the support library, do this:
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
Notice how the style name does not include the android: prefix.
I used Theme.Sherlock.Light.DarkActionBar for my whole Application. Now the Action bar background color is black by default. How to change this color. Basically how to customize the Theme for whole Application?
<activity
android:name="com.mypath.myapp.FirstActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light.DarkActionBar"
>
You can use android:theme=theme_style in your <application> tag. Now if you want your action bar to be different than that given by the theme, then you can override it by defining the style between <style></style for your action bar specifically.
Here's the concept. Go to res > values > styles.xml. You can extend or customize your themes as follows:
<style name="AppBaseTheme" parent="android:Theme.Light">
<item name="android:background">#color/background_dark</item>
</style>
Update:
OR if you want to make generic (not theme specific) changes for all your applications, then you can edit sdk/platforms/android-target/data/res/values/styles.xml
OR if you want to override default themes for all your applications, then you can edit sdk/platforms/android-target/data/res/values/themes.xml
Update - found this:
ActionBar developer docs. This link says "You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11)." So I assume your target is API 11 at minimum.
If you are targeting API 11 and above, you can do advanced custom styling as follows:
<resources>
<style name="CustomActivityTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_background</item>
<item name="android:backgroundStacked">#drawable/ab_background</item>
<item name="android:backgroundSplit">#drawable/ab_split_background</item>
</style>
</resources>
Here you go , Styling Action Bar background
You can define the theme for your whole application in your manifest file in application tag as below:
<application
android:name="com.test"
android:icon="#drawable/appicon"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" > <---Define your own style here.
Have a look at http://actionbarsherlock.com/theming.html . You must create a own Theme-style.
for modifying default android sdk themes You can find android Sdk themes.xml file in :
\android-sdk\platforms\...\data\res\values\themes.Xml
so you can change your whole application theme.