I've done research on this but can come to no answer why my statusbar is white in my Splashscreen. It works great in my MainActivity, which the theme, according to my Manifest, is also "#style/AppTheme.NoActionBar". Both my splashscreen and mainactivity have the same theme.
I want the statusbar to be colorPrimaryDark.
styles.xml
<!-- 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>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="RainImage">
<item name="android:src">#drawable/no_rain</item>
</style>
<style name="BirdImage">
<item name="android:src">#drawable/one_bird</item>
</style>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".SplashScreen"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Just past the following code on styles.xml(v21) file
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style>
Related
I have found similar questions but the answers did not work. I do not want to change the colorPrimary.
The ActionBar is not a ToolBar, so it does not exist in the activity's layout XML. The following did not work, and the bakground was still set to colorPrimary.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#color/colorBlack</item>
<item name="android:colorBackground">#color/colorBlack</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:backgroundStacked">#color/colorBlack</item>
<item name="android:backgroundSplit">#color/colorBlack</item>
<item name="android:background">#color/colorBlack</item>
</style>
</resources>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Programmatically you can do
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#YOUR_COLOR")));
I'm trying to edit the Title text size because it changes when in landscape screen. I found changing the dimension in SP can solve the problem. So I did this...
added a style in style.xml
<style name="Toolbar.TitleText"
parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">30sp</item>
</style>
and then in app_bar_main.xml under android.support.v7.widget.Toolbar i added this line
app:titleTextAppearance="#style/Toolbar.TitleText"
Now it gives the desired result on Main activity but all others activities are same. I have around 10 activities in my app. How can I change all the activities' Title? Please help. Thanks in advance.
my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/title_main"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".splash"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ch_1"
android:label="#string/ch_1" />
<activity
android:name=".ch_2"
android:label="#string/ch_2" />
<activity
android:name=".ch_3"
android:label="#string/ch_3" />
<activity
android:name=".ch_4"
android:label="#string/ch_4" />
<activity
android:name=".ch_5"
android:label="#string/ch_5" />
<activity
android:name=".ch_6"
android:label="#string/ch_6" />
<activity
android:name=".ch_7"
android:label="#string/ch_7" />
<activity
android:name=".ch_8"
android:label="#string/ch_8" />
<activity
android:name=".ch_9"
android:label="#string/ch_9" />
<activity
android:name=".ch_10"
android:label="#string/ch_10" />
<activity
android:name=".ch_11"
android:label="#string/ch_11" />
<activity android:name=".ch_12"
android:label="#string/ch_12" />
<activity
android:name=".ch_13"
android:label="#string/ch_13" />
<activity
android:name=".ch_14"
android:label="#string/ch_14" />
<activity
android:name=".ch_15"
android:label="#string/ch_15" />
<activity android:name=".view" />
</application>
my style.xml
<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>
<item name="android:windowBackground">#color/white</item>
<item name="colorButtonNormal">#color/colorPrimary</item>
<item name="android:textAppearanceButton">#style/TextAppearance.AppCompat.Button.Custom</item>
</style>
<style name="Toolbar.TitleText"
parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">24sp</item>
</style>
<style name="TextAppearance.AppCompat.Button.Custom">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">28sp</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ActionButtonStyle" parent="#android:style/Widget.Holo.ActionButton">
<item name="android:minWidth">0dip</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingRight">0dip</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
</style>
You can use <include> tag to achieve it.
Just like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.dzq.aprivate.view.activity.MainActivity">
<include layout="#layout/lay_actionbar"/>
<FrameLayout
android:id="#+id/lay_container"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<include layout="#layout/lay_main_bottom"/>
</LinearLayout>
Use <include layout="#layout/toolbar_header"/> in every Activity you want.
Ok, I have resolved the issue. The previous code was not working for other layouts because activity_main.xml was using toolbar instead of action bar, so i had to write another piece of style for the action bar.
I added these style..
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">24sp</item>
</style>
and then added the item in AppTheme like this..
<item name="actionBarStyle">#style/MyActionBar</item>
and it's working fine now. Thanks everyone for replying.
this is my manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<service android:name="com.amap.api.location.APSService" />
<activity
android:name=".MainActivity"
android:label=""/>
<activity
android:name=".QueryActivity"
android:label="" />
<activity
android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegistActivity" />
<activity
android:name=".TaskListActivity"
android:label="" />
<activity
android:name=".TaskWatcherActivity"
android:label="" />
<activity
android:name=".DetailsActivity"
android:label="" />
</application>
i have set the style in style:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlNormal">#color/cpb_white</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
&style-v21:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:textSize">15sp</item>
<item name="android:colorControlNormal">#color/cpb_white</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
but only the mainactivity's status bar is in colorprimarydark,other activities' statusbar is in the color of their layout's background. so how can i make colorprimarydark work for every activity's status bar
Very easy and useful library for Tint Color use this library in every Activity set you status color.
Try to Use android:theme="#style/AppTheme" in each and every activity.
I think you solve your problem.
finally, i used the library for Tint Color to solve the problem, p.s.thasks to Jhaman Das.
And i found that the attr of statusBarColor would cover the effect of colorpromarydark, it is the drawlayout that can have the ideal effect. willing to get further discussion on this problem.
This is my android manifest
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
>
<activity
android:name=".splash"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DrawingActivity"
android:parentActivityName="com.example.kahheng.smartchat.MainActivity"/>
<activity
android:name=".pollActivity"
android:parentActivityName="com.example.kahheng.smartchat.MainActivity"/>
<activity
android:name=".bookmarkActivity"
android:parentActivityName="com.example.kahheng.smartchat.bookmarkActivity"
android:label="Bookmark Page"
/>
<activity
android:name=".ContactListActivity"
/>
<activity
android:name=".MainActivity" />
</application>
This is my style file
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="android:Theme.Material.Light">
<item name="android:background">#255e7c</item>
</style>
<style name="ContactListTheme" parent="android:Theme.Material.Light">
</style>
</resources>
How to make my app name appear on the android:actionBarStyle?
if I apply the the actionbar theme to my activity, the whole screen will change into that colour.
I not sure what is happening.
It is okay when it was default, the word on the actionbar is gone when I apply the style for actionbar.
I have two XML file, activity_main and content_main.xml
How to do manually define title for a actionbar in XML?
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
//this 2 line remove actionbar
// <item name="windowActionBar">false</item>
// <item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<style name="MyActionBarTheme" parent="android:Widget.Material.Light.ActionBar">
//<style name="MyActionBarTheme" parent="android:Theme.Material.Light">
<item name="android:background">#255e7c</item>
</style>
<style name="ContactListTheme" parent="android:Theme.Material.Light">
</style>
</resources>
I have a problem with StatusBar, I've managed to implement styles for it like this:
<resources>
<style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">#59000000</item>
<item name="android:statusBarColor">#59000000</item>
<item name="colorAccent">#color/blueAppBar</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
But activity doesn't work with it properly and goes like this:
As you see status bar is not tinted and goes just blue, like background. What should I do to make it tinted?
You shouldn't use android:windowTranslucentStatus and android:statusBarColor together.
You should use android:windowTranslucentStatus in values-v19 and android:statusBarColor in values-v21.
This is a sample configuration:
values/styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">#59000000</item>
<item name="colorAccent">#color/blueAppBar</item>
</style>
<style name="AppTheme.NoActionBar">
</style>
</resources>
values-v19/styles.xml
<resources>
<style name="AppTheme.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
values-v21/styles.xml
<resources>
<style name="AppTheme.NoActionBar">
<item name="android:statusBarColor">#59000000</item>
</style>
</resources>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>