Android API 16 not fitting windows when status bar is shown - android

Is there any reason why a View is partly hidden (API 16) when the Activity has a status bar?
In this activity, I added a view that has a red border.
The red border on the bottom should be shown. If I added a bottom margin of 24dp (which is the height of the status bar), the bottom border is shown. Which indicates that the view height isn't properly set.
The code is like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:id="#+id/rootView"
>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/red_border"
/>
</LinearLayout>
And the activity theme is
<?xml version="1.0" encoding="utf-8"?>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorControlHighlight">#0D53CE</item>
<item name="android:windowTranslucentStatus" tools:targetApi="19" >true</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowBackground">#color/windowBackground</item>
<item name="android:popupMenuStyle">#style/MyPopupMenuStyle</item>
</style>
It works when I set:
<item name="android:windowFullscreen">true</item>
But then the status bar isn't there.
This bug only happens in Android 16 that I've tried, in Android >= 21, this doesn't happen.
Thanks :)

Related

android - how to set gradient for statsbar without effecting navigationbar?

I'm trying to add a gradient to my statusbar , this is my code :
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
it moves up the toolbar on the status bar and also covers up the navigation bar with the activity's content like this . I made my toolbar height bigger and solve the first problem but is there any way to preventing this code covering my navigation bar ?
anyway , is there any better way to add gradient to my statusbar without changing the toolbar height ?
Just follow the following thing it will work for you, in my case its working perfect
Make layout like bellow
main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:background="#mipmap/ic_launcher"
android:fitsSystemWindows="true"
tools:context=".SplashActivity">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_150sdp"
app:layout_constraintEnd_toEndOf="parent"
android:src="#drawable/cell_background"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_height="#dimen/_150sdp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
and bellow tow flags
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Apply bellow theme to your screen
<style name="AppThemeTrans" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#android:color/transparent</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlNormal">#FFFFFF</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:navigationBarColor">#color/navigationBarColor</item> <!--Change Navigationbar background color here-->
</style>

keep the icon original size on android action bar

<style name="ActionBarStyle"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/pink</item>
<item name="android:icon">#drawable/header</item>
<item name="android:displayOptions">showHome|useLogo</item>
<item name="android:titleTextStyle">#style/ActionBar.TitleTextStyle</item>
<item name="android:height">79px</item>
</style>
Above is my action bar style. the icon's original size is 41px in height. What i want is to keep the original size and center it vertically in the cation bar. But right now, the icon is stretch to fill the 79 px in height. Is it by default to stretch the icon to fill the space or what ?
Please point me to the right direction to solve this, Thanks in Advance.
Add an <item> like this to your action bar:
<item
android:title="my_icon"
app:actionLayout="#layout/my_icon_layout"
app:showAsAction="always"
/>
Notice the my_icon_layout line.
Create a my_icon_layout.xml in your res/layout folder that looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="41px">
<ImageView
android:src="#drawable/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
/>
</RelativeLayout>
Should work for you.

AppCompat Dialog theme's margins and background with circular reveal

I am having some difficulties..
I want to mimic Floating Search Widget as seen in Google I/O 2015 app - seen bellow.
So far I managed to put my second(search) activity into a dialog with Theme.AppCompat.Light.Dialog theme. I followed the steps shown here https://stackoverflow.com/a/32199671/2674529 to ger circular reveal effect working.
Second activity style is defined in Theme.Transparent
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowIsTranslucent">false</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="windowNoTitle">true</item>
</style>
Note: Greenish color is green color with alpha and is the background of the root layout of the second activity.
The problem is transparency of the dialog's background.
If I comment out the
<item name="android:windowBackground">#android:color/transparent</item>
from the theme, then the dialog's background is whitish - as seen bellow.
If I uncomment the line I get a "dialog" without any border nor margin - seen bellow.
Does anyone have any ideas? Thanks
PS. xml of the dialog/activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8800FF00">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>

Android - set action bar height as a fraction of total height

I am developing an Android application that has an action bar. I know how to set height of action bar in pixels, but I would like to set action bar's height to be 15% of screen's height. Is that possible? Here is what I have so far in my resources file:
<!-- Application theme. -->
<style name="CustomActionBarTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions">showHome|useLogo</item>
<item name="android:background">#color/white</item>
<item name="android:height">90dp</item>
</style>
You can use below code, to set custom height of ActionBar,
Compatible toolbar for previous versions of Android,Custom height is set in my case i set 100dp instead of 48dp default.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bg"
android:gravity="center_horizontal"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:background="#e5e5e5"
android:popupTheme="#android:style/ThemeOverlay.Material.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_alignParentTop="true"/>
<-- Your other component or xml code goes here...!-->
</LinearLayout >

changing the titlebar results in not showing (fonts issue) the listview items

I want to change the title bar color .Following the instructions here
, or eliminating the title bar with Notitle bar in AndroidManifest esults in not showing the text fonts in the list view (I use "simple_list_item_checked" listview).
Here is the xml for this activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFAFA"
>
<Button
android:id="#+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/green_button"
android:text="#string/show_items_kfc"
android:onClick="onClick"/>
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
(the rest of xml code is the same as the link above)
Any solutions to this?
Thanks!
If I got the problem:
Instead of parent="android:Theme":
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
Use parent="android:Theme.Light":
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="android:Theme.Light">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
The problem is that you are overriding the native Black theme which has black background and white letters. By switching to Light theme you achieve the black letter also have your own white background!
Note: After that you may have to fix custom theme colors (eg. title text color force to white) to white/black if they do not fit the UI you need.
you can use the titlebar object for the purpose...
the link below gives the good explanation on how to do that...
Title bar color change issues

Categories

Resources