Trying to make Status bar and Navigation bar translucent, not transparent - java

I'm trying to make my first app for a school project. I got the status bar translucent at times by following other people questions and answers but the nav just goes grey but with no contents from the activity BUT the navigation drawer draws below both status and navigation bar, how can I make the activity to draw below status and nav bar as well?
enter image description here
enter image description here
code for image 2 is, under onCreate:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
And I tried with android:fitsSystemWindows="true" and without, kinda hard to understand it all already.

Pretty much solved by adding these two lines in styles.xml
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
Not the most elegant because I don't have a proper toolbar? I think. I need to put android:layout_marginTop="24dp" in activity_main.xml and pretty much everywhere else where I may have buttons at the top of the app.

Related

Fixed background while switching layouts

I got my application uploaded and I see that despite I have the same background image on all my layouts.
if I switch, the layout moves according to the animation.
Is there a way for me to set a fixed background for all my layouts?
Does it matter that I finish(); every layout before I switch to the next one?
Setting the same background to all the layouts doesn't make it fixed (it moves)
neither does creating a style like :
<style name="AppTheme.FullBackground" parent="AppTheme">
<item name="android:background">#mipmap/background</item>
</style>
and adding :
android:theme="#style/AppTheme.FullBackground"
to the manifest.
Any ideas?
If you are using all activities in your app then change all activities to fragment and just use one activity with your required image as background.
Then use just this activity for all the fragments in your app. This will not move your background image during navigating to different screens(fragments)

Android Status bar and Navigation issues

Recently I used this java code in Main_Activity:
(getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS))
for status Bar Transparent purpose. All went well, but my Android Navigation Bar also went to transparent policy.
Now I need only transparent my Status Bar, but not the Navigation Bar.
You have two options to do, first, one which I recommend for you would be using an external library for status-bar styling like StatusBarUtil library, which enables you to fulfill your requirement in just one line:
StatusBarUtil.setTransparent(Activity activity) // yo be placed in every activity you want the status bar to be transparent in
And this library doesn't affect the navigation bar.
Just make sure first to implement the library in your app level Gradle:
implementation'com.jaeger.statusbarutil:library:1.5.1'
Second option, is to go for layout customization, as mentioned in this tutorial, you can add the following to your style.xml:
<style name="AppTheme.TransparentTheme">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
And apply this style to the Activity in the manifest:
<activity
android:name=".HomeActivity"
android:theme="#style/AppTheme.TransparentTheme">
</activity>
As described in the tutorial:
I have set android:windowDrawsSystemBarBackgrounds to true.
This is a flag whose description is given below:
Flag indicating whether this Window is responsible for drawing the
background for the system bars. If true and the window is not
floating, the system bars are drawn with a transparent background and
the corresponding areas in this window are filled with the colors
specified in {#link android.R.attr#statusBarColor} and {#link
android.R.attr#navigationBarColor}. Corresponds to {#link
android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS}.
Don't forget to add the attribute android:fitsSystemWindows="true" to the top root of your activity layout.

Screen turns black on touching a view? what should i do to fix this?

Everytime,I touch on a view or menu item, navigation item or anything on the screen, the screen turns black for a second(or less) and then opens another activity or Fragment. I have seen similar type of question(that is regarding scrolling a list), Does "cacheColorHint" attribute works here?
try adding this to your theme:
<item name="android:windowDisablePreview">true</item>
or , Try this in Manifest.. inside your activity
android:theme="#android:style/Theme.Translucent"
Or
android:theme="#android:style/Theme.Light"

Overlay image on Action Bar

How do I overlay image over an Action Bar and status bar? Here is what I want it to look like -
I read this but it gives different results than what I want. The Action Bar still has some opacity and the status bar has no effect at all.
Is there any way to do this?
Add these two lines of code to your styles-v21.xml file:
<item name="android:windowTranslucentStatus">true</item>
<item name="windowActionModeOverlay">true</item>
Edit:
You want it in the v21 file because Android versions below 5.0 don't support this.
Also...for Material Design, you should be using a ToolBar not an Action Bar. Here's how to change the color of a Toolbar.
toolbar.getBackground().setAlpha(0);
Check this answer.
This one worked perfectly in my project.
This library is also great to explore:
https://github.com/ManuelPeinado/FadingActionBar

How to change the background colour of the spinner on the aciton bar

I'm working on an android app and have come across an issue, I have managed to get the list items on the action bar to highlight to the color i want but the 'spinner' area around the item is staying the default blue, does anyone know how i can change this color?
I've fixed it!
I used this website which allows you set colors etc. for your action bar and then you just put them in your drawables folder and link it up with the style sheet.
I'm not sure if its the cleanest fix but it works.
http://jgilfelt.github.io/android-actionbarstylegenerator/
Try using android:background within your spinner.
Try this:
(without Sherlok)
<style name="Theme.MyTheme" parent="#style/YourTheme">
<item name="android:selectableItemBackground">#drawable/ab_selector</item>
<item name="android:actionBarWidgetTheme">#style/WidgetStyle</item>
</style>
<style name="WidgetStyle" parent="Widget">
<item name="android:itemBackground">#drawable/ab_menu_selector</item>
</style>

Categories