Overlay image on Action Bar - java

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

Related

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.

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.

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

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>

Number of tabs in ActionBar

Android's ActionBar has a mode NAVIGATION_MODE_TABS. Using ActionBarSherlock 3.5.1 I have set this ActionBar and addded 5 tabs. On 2.x devices I see all tabs without horizontal scrolling. On 4.0.x I see only 3 tabs with scrollable layout. NAVIGATION_MODE_TABS of ActionBar can contain max 3 tabs in ICS? If yes, could I hack this somehow? I know, i could create custom TabHost, but it would be quite time consuming to implement it with ViewPager between tab views.
You don't need to hack anything. The ActionBar tabs have specific layout parameters that you can change pretty easily through a custom style. Google uses their own style to set them in the first place. You should take a look at this on creating custom styles. http://android-developers.blogspot.com/2011/04/customizing-action-bar.html Since you want them to look like they way Jake Wharton has them set in ActionBarSherlock, then you could make things even easier for yourself and just rip his styles out.
I had the same problem with action bar sherlock, and this post helped me.
How to manage the width of ActionBar navigation tabs?
Important part is
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>

Categories