android - Bug Status Bar and navigation Bar TRANSPARENT - android

I have a problem with the translucent statusbar only when opening of the app for the first time. Take a look at the screenshot:
http://i1335.photobucket.com/albums/w673/ductruongcntt/Screenshot_2014-06-26-14-17-26_zps1e9a56f4.png
Here is the XML of the Style I use which is including the translucent Status Bar:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fitsSystemWindows="true"
android:orientation="vertical" >
<com.viewpagerindicator.PagerSlidingTabStrip
android:id="#+id/indicatorTabHome"
android:layout_width="match_parent"
android:layout_height="40dp"
android:clipToPadding="false"
android:fitsSystemWindows="true" >
</com.viewpagerindicator.PagerSlidingTabStrip>
<android.support.v4.view.ViewPager
android:id="#+id/vpMain"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
and my theme:
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTranslucentStatus">true</item>
</style>

Put this inside your activity tag in the manifest. This'll ensure that the app opens full screen.
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"

Related

Android status bar is shadow

I just want bring my navigation drawer under status bar every thing works fine but problem is my status bar is shadow .
How can i change it to transparent , like play store app .
Here is my app theme
<item name="colorPrimary">#color/colorPrimaryDark</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#android:color/white</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">?attr/colorControlHighlight</item>
and main activity xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The ActionBar displayed at the top -->
<include
layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="0dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tab_layout"/>
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="#+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:headerLayout="#layout/nav_header"
android:fitsSystemWindows="false"
android:layout_gravity="start"
app:menu="#menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
You can simply change Android status bar color as transparent.
this will help you.
Window window = activity.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
/*----set color----*/
window.setStatusBarColor(activity.getResources().getColor(R.color.my_statusbar_color));
ok i fix it my self if you have similar problem remove all these lines from your theme
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
and just add
android:fitsSystemWindows="true"
to your main liniear layout

Activity-based action bar/status bar visibility

I am trying to set up the action bars and the status bar within my app, however I have run into an issue. I did have it working, but it wasn't a clean way of doing things, so I decided to start over.
On the launch activity I want the status bar to be visible, with the pink background that I'm using throughout the app (no action bar). On the next view I want both the action bar and the status bar.
This is what I have within my launch activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
tools:context="com.andrewnwalker.mousetimes_california.ParkSelectActivity">
<LinearLayout
...>
<TextView
.../>
<TextView
.../>
<Button
.../>
<Button
.../>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
And this is what I have in the second activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.andrewnwalker.mousetimes_california.MainActivity">
<android.support.v7.widget.ActionBarContainer
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<include layout="#layout/content_main"/>
</android.support.design.widget.CoordinatorLayout>
And in content main:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.andrewnwalker.mousetimes_california.MainActivity"
tools:showIn="#layout/activity_main">
<android.support.v4.widget.SwipeRefreshLayout
...>
<android.support.v7.widget.RecyclerView
..../>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
And finally in styles:
<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:typeface">serif</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" />
It's probably a bit of a mess, but I'm pretty confused by the settings for styles and action bars. Can anyone suggest the changes I can make to do what I'm looking for?
At the moment the first activity has shows the status bar text, but no background colour, and the second activity shows the status bar and action bar, but it also contains a menu item, which I don't want.
Thanks!
The status bar color conforming to material design is driven by the app's theme. You can read the official docs about this, as there's not enough information here to know for sure what's going on. You might be overriding the app theme on the first activity in the manifest or changing it somehow in the activity. The first activity does have a peculiar layout. There's no need to use CoordinatorLayout here if you don't have an action bar. If you just need to scroll the inner LinearLayout, just use a ScrollView instead.
To remove the action bar menu, make sure that you're not returning a menu in onCreateOptionsMenu or modifying anything in onPrepareOptionsMenu. Remove those methods if they're not needed.

Support Toolbar title/menu vertical centre

I'm new to android development and I'm working on an app with ActionBar and Tabs. Recently I switched to the new support library Toolbar but the title of the toolbar (ActionBar) isn't vertically centred, while the action buttons are correctly placed.
Title image
The same problem occurs with the first MenuItem in the bar (it's moved up a little bit). Menu image
My activity extends the AppCompatActivty and the layout looks like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/action_bar_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ActionBarTheme"/>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabMode="fixed"/>
<com.myApp.app.views.widgets.ViewPager
android:id="#+id/fragmentPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
and the style:
<style name="ActionBarTheme" parent="Widget.AppCompat.Toolbar">
<item name="android:textColorPrimary">#color/colorPrimaryDark</item>
<item name="colorControlNormal">#color/colorPrimaryDark</item>
<item name="android:background">#color/colorPrimary</item>
</style>
Could someone help me fix this issue? I've searched for a solution but found nothing.
P.S. They were correctly placed as I was using the default action bar
You should use android:theme rather than app:theme here:
android:theme="#style/ActionBarTheme"
Your style should derive from the action bar overlay:
<style name="ActionBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
...
</style>
Consider just using the ActionBar theme directly to start to isolate the problem.

Android Swipe Tabs without Action Bar By Using Vertical Layout On Screen

Here is my code in onCreate() function;
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
The problem is that, When I write and compiler this code, I cannot get the result which I wanna see on the screen. I just want to see the swipe tabs without action bar.
Here is the result by image;
enter image description here
Remove your ActionBar and use TabLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill" />
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.voidynullness.android.tabitytabs.TabLayoutActivity">
</android.support.v4.view.ViewPager>
Edit your styles.xml under res - > values - > styles.xml and set parent to parent="Theme.AppCompat.Light.NoActionBar"
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
and remove
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
from onCreate() of Activity

Making the statusbar have a color, yet be transparent

This is my current layout in action:
The xml file producing this looks like:
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/toolbarTheme"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
</LinearLayout>
<include layout="#layout/drawer"/>
</android.support.v4.widget.DrawerLayout>
The style that the theme uses:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<item name="android:colorAccent">#color/accent</item>
<item name="android:statusBarColor">#color/primary_dark</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
The expected result was that the status bar would be colored in the primary_dark color, yet the drawer should be on top of it (like in Google apps), yet I get this result. How do I fix this?
You need to make sure your activity has android:fitsSystemWindows="true" and maybe android:clipToPadding="true"but bare in mind this is for later version of android only

Categories

Resources