Android Status bar and Navigation issues - java

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.

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)

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

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.

How can i change android actionbar picture

i am new on android and i am using android studio to develop. i want to change actionbar top right corner button image to another one but after compile to my android device the button still remain the ... but my customize image. please help!! below is my code. my public class is extend activity.
menu.xml
android:id="#+id/action_share"
android:orderInCategory="100"
android:title="Share"
android:icon="#drawable/ic_search_black"
app:showAsAction="ifRoom"
Vic3ai, That icon all the way to the right is the Action Overflow and it will always show a drop down list of action buttons that don't fit on the actionbar (either because there isn't room or because we decided to put some in the overflow on purpose).
This might give you a better idea of what the overflow is and is used for, as well as a general overview of the actionbar - http://developer.android.com/design/patterns/actionbar.html.
It sounds like what you actually want is to add an action button to your action bar. You can do that like so:
First add a new item in your menu.xml for which ever activity you want it to appear in:
<item
android:id="#+id/camera_button"
android:title="#string/camera"
android:icon="#drawable/camera_icon"
android:orderInCategory="100"
android:showAsAction="always"
/>
Here the important thing is android:showAsAction="always". This is what makes it appear as an action button on the action bar. You could also use value 'ifRoom', which does what it says on the tin: If there's room on the actionbar the button will display, otherwise it goes into the action overflow.
Now that we have the actionbutton in existence we go to our actvity.java and respond to the button:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.camera_button:
//your code here, eg:
openCamera();
return true;
// if you have other buttons, more cases would go here
}
return super.onOptionsItemSelected(item);
}
So far this should give you an Action Button on the actionbar that will run whatever could you define in your activity.java but the action overflow will still be there. The easiest way to remove it is to go back to your menu.xml and remove/change any items that would appear in the overflow.
android:showAsAction="never"
will automatically put action in to the overflow
If you have a lot of action buttons and any of them have android:showAsAction="ifRoom", you might find an overflow button on the far right again
NOTE, use app:showAsAction="always" instead of android namespace if you're using appCompat compatibility.
Hope this helps!
To change the Action Overflow Icon - default is three vertical dots - you have to add an actionOverflowButtonStyle item to your main theme declaration AND then define it in styles.xml:
<resources>
<!-- base application theme -->
<style
name="AppTheme" parent="#android:style/Theme.Holo">
<!-- include overflow style in theme -->
<item name="android:actionOverflowButtonStyle">#style/OverFlowIcon</item>
</style>
<!-- styles -->
<style
name="OverFlowIcon"
parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/ic_search_black</item>
</style>
</resources>
Of course if you're using AppCompat themes don't forget to use atributes without the android namespace or it wont work - ie
<item name="actionOverflowButtonStyle">#style/OverFlow</item>
instead of what you see above.
Also don't forget to include your theme in application tag of AndroidManifest.xml if you change make a custom theme:
<application
android:name="com.example.android.MainApp"
android:theme="#style/AppTheme">
</application>

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

Implement a bar with some buttons in android

I'm having some difficulties to reach a way of implementing an layout that i want for a android project. I have to make a layout like this:
This bar is at the top of the android screen over a map of google and each icon are a button. The map is already in the layout at this time.
Whats the simple way of doing this with android layout?
After that and not so important at this time, after click each button i have to open a rectangle with some options to fill (text boxs and dropdown lists) but i know that i can do this with a alert dialog. Is this the best way for doing this part?
Regards for the help
you can use third party libraries for this. ActionBarSherlock is the library which you can use.
Here's a link Click here to download
and for tutorial follow this link.
thanks
You can use an Action Bar, and overlay it on top of the map.
To enable overlay mode of the action bar, you have to create a custom theme and modify some values:
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
More information on this in this android documentation

Categories