How to make a transparent status bar in Android 4.4? - android

I want to make a transparent status bar in my application in Android 4.4.
How do I do that?
I tired:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/skipPrimary</item>
<item name="colorPrimaryDark">#color/skipPrimary</item>
<item name="colorAccent">#color/skipPrimary</item>
</style>
and in the manifest:
<application
android:name=".App"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme" >
and in the activity:
<activity
android:name=".activities.StartActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"
android:windowSoftInputMode="adjustResize|stateHidden" />

This one will throw exception on Lollipop devices. primColor must be opaque.
<item name="primColor">#android:color/transparent</item>
Style your actionbar using style.xml
<style name="ThemeActionBar"
parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:background">#null</item>
<!-- Support library compatibility -->
<item name="background">#null</item>
</style>
Include you theme..
<item name="android:actionBarStyle">#style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/ThemeActionBar</item>
<item name="windowActionBarOverlay">true</item>

What you can also do is set the status bar a darker shade of your background or even the same color by setting it in your activity.
You can set the status bar color in your activity with the following code getWindow().setStatusBarColor(getResources().getColor(R.color.your_color));.
If you want to use a darker shade of your color you can do it by changing your color's HSB. For a more detailed way of doing that you can read this post: Android change status bar color by converting existing color's HSB

Related

Android appcompat theme always shows black color actionbar

I generated actionbar style using this web based tool which is very common
http://jgilfelt.github.io/android-actionbarstylegenerator/
I've 'android-support-v7-appcompat' as an individual project in my workspace. I dumped all the contents of the res folder generated by downloading the zip file from this tool into this project.
I used a dark blue kinda color for the action bar and context menu (pop up).
However, I'm not able to achieve the custom look from this theme. Most of the elements / components show a default look.
The actionbar is black (instead of blue) and the pop menu is grey (instead of light blue)
My style.xml from the value folder
<style name="Theme.dinemobileandro" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarItemBackground">#drawable/selectable_background_dinemobileandro</item>
<item name="popupMenuStyle">#style/PopupMenu.dinemobileandro</item>
<item name="dropDownListViewStyle">#style/DropDownListView.dinemobileandro</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.dinemobileandro</item>
<item name="actionDropDownStyle">#style/DropDownNav.dinemobileandro</item>
<item name="actionBarStyle">#style/ActionBar.Solid.dinemobileandro</item>
<item name="actionModeBackground">#drawable/cab_background_top_dinemobileandro</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_dinemobileandro</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.dinemobileandro</item>
<!-- Light.DarkActionBar specific -->
<item name="actionBarWidgetTheme">#style/Theme.dinemobileandro.Widget</item>
</style>
I've made the necessary changes in my manifest file as well
<application
android:name="com.railyatri.in.mobile.MainApplication"
android:allowBackup="true"
android:allowClearUserData="true"
android:enabled="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.dinemobileandro" >
I've followed the steps mentioned in this blog closely and it worked for me previously for a sherlock theme.
http://java.dzone.com/articles/creating-custom-android-styles
However, this time, I migrated to appcompat and it stopped working. I've searched through SO and Google a lot and tried a couple of things suggested but all in vain.
Please help. Thanks in advance.
With AppCompat v21 the actionbarstylegenerator is deprecated.
You can use something like this to customize the ActionBar (or better the Toolbar).
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat's color theming attrs -->
<item name="colorPrimary">#color/my_color</item>
<item name="colorPrimaryDark">#color/my_darkercolor</item>
</style>
You can find more info in the official blog:
http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-pre.html
Have your already tried to change on your Java file?
Something like this:
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setTitle(Html.fromHtml("<font color=\"grey\">" + getString(R.string.app_name) + "</font>"));
getSupportActionBar().setBackgroundDrawable(..);
On Android manifest:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.dinemobileandro" >
On styles xml:
<style name="Theme.dinemobileandro" parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/blue</item>
<item name="background">#drawable/blue</item>
On drawables xml:
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<drawable name="blue">#6189C5</drawable>
</resources>
The toolbar on activity is blue (#6189C5) compiling with API 21
Completed with the info in this answer (like Apurva appointed)
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/my_actionbar_color</item>
<item name="colorPrimaryDark">#color/my_actionbar_dark_color</item>
<!-- if you need customization -->
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>
Remember to use
parent="Theme.AppCompat.Light"
not
parent="#style/Theme.AppCompat.Light"

Changing Android action bar background colour

For some reason this setup just gives me the default action bar background colour.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#d73830</item>
</style>
</resources>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...
</application>
In activity_main.xml my theme is set to 'AppTheme'.
You have wrong parent of MyActionBar.
It must be from AppCompat, like next:
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">#color/red</item>
<item name="background">#color/red</item>
</style>
What you can do is to use hash code of colour.Here is how.Go to this web page
http://www.color-hex.com
Choose a colour you wish and after copy the code of that colour and later paste into your background section.In general lets say you want your background colour of your screen to be red so you must declare it in xml layout file like this
android:background = "#FF0508"/>
You can declare this code almost everywhere where you want to change exact things colour and for my opinion its the easiest way.Why not?you got a webpage where you can get colour code and you can use it with a single line everywhere.Delicios isn't it?

Android customize AppCompat ActionBar

I have seen multiple threads on this but I am unable to find the solution to my problem. I want to create a custom action bar so to begin I just tried something simple like just a custom color:
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
Then in my Manifest I have:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
My MainActivity also extends ActionBarActivity
I was getting an error saying that I need to apply Theme.AppCompat to my Activity but I am no longer getting that error. My application compiles and runs but the action bar is just standard black, not red (#FF0000).
Eventually I want to make my action bar transparent but I figured I would get this sorted out first. Any help would be appreciated.
As said in the documentation, for retro-compatibility, you should use actionBarStyle along with android:actionBarStyle:
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
If you want flexibility use Toolbar instead of ActionBar. I dont think you can make the default action bar transpatent, and you can achieve that with Toolbar. Read more here http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html
With new AppCompat-v7 (v21) ActionBar style's properties need to refer to the app namespace, that is without android: prefix.

Android theme: Whole screen becomes white

I am doing a simple customization to my app where I want to add a custom background color to Action Bar. Here is my styles.xml in styles-v14 folder. (My app is targeting only SDK 14 and above).
If I simply uncomment this line and run my app , the whole screen becomes white except status bar while I expect the Action Bar background color to be of different color.
<!-- <item name="android:actionBarStyle">#style/WindowTitleBackground</item> -->
Any idea what is going wrong. Here is my App manifest:
<application
android:name=".App"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
styles.xml
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:listChoiceIndicatorSingle">#drawable/btn_radio_holo_light</item>
<!-- <item name="android:actionBarStyle">#style/WindowTitleBackground</item> -->
</style>
<style name="RadioButtonAppTheme" parent="android:Widget.CompoundButton.RadioButton">
<item name="android:button">#drawable/btn_radio_holo_light</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">#color/titlebackgroundcolor</item>
</style>
</resources>
Try adding parent attribute in your ActionBar style
<style name="WindowTitleBackground"> parent="#android:style/Widget.Holo.ActionBar"
<item name="android:background">#color/titlebackgroundcolor</item>
</style>

Trying to set the background of android actionbar version 2.1 or so (API 7) and up

Alright so I've followed android tutorial to try and style my action bar and it doesn't seem to work
themes.xml
<resources>
<!-- the theme applied to the application or activity -->
<style
name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style
name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
...
I made sure i have actionbar_background.png(which is an square image with a color basically) in the correct folders. however. when i run the up i still see the old action bar like nothing changed.

Categories

Resources