I'm trying to incorporate Google's LeftNavBarLibrary into my application. When I load the nav bar I end up with a black bar across the top of the activity. The bar appears to be taking up the space a traditional actionbar would occupy.
Does anyone know where the bar is coming from or how to remove it.
Thanks.
My application theme is slightly customized. Based on the AppCompat theme due to requirements of the MediaRouteActionProvider
styles.xml
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/ab_gradient</item>
</style>
</resources>
The activity pictured above has a custom theme defined in the manifest.
AndroidManifest.xml
<activity
android:name="my.app.namespace.CoreActivity"
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
</activity>
The applications minimum sdk version is 14. So it's not exclusively a Google TV app. I've only been able to test this bug on my Android 4.1 and 4.4 devices.
I deal with the action bar this way:
getActionBar().hide();
Try to put this in your main activity or the activity that is the parent and always present.
Don't bother about the theme in manifest, just set your theme with title bar and hide it through the code.
Hope this helps.
Take a look at: Hide the Status Bar on Android 4.0 and Lower
Notice that this is in the <application> tag. That might help you.
<application
...
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
or programmatically:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
You can set android:windowActionBar style to false by setting custom theme.
Note: In this case getActionBar() will return null. If you remove the action bar using a theme, then the window will not allow the action bar at all.
Thanks for the answers guys. The real issue was actually that the LeftNavBar.java class was creating an artificial margin at the top of the screen. I'd have thought that a google published library would be better than that, but apparently not.
Related
First off, I'm not completely sure that Title Bar and Action Bar are the same? 2 different things?
I have an existing application that I need to maintain. In I have an activity that had a custom view as a title. What I want is to have the default title bar for the activity - the native one. I removed the custom view, and in the activity class I removed requestWindowFeature(Window.FEATURE_NO_TITLE); but the activity still doesn't show the Title bar. I've set the activity theme to android:theme="#style/Theme.AppCompat.Light". Still no Title Bar.
The activity intent is started with launchActivityForResult - don't know if that has anything to do with that.
What am I missing here? Is there a way to show it programmatically?
title-bar and action-bar is different thing.
use theme like this.
Theme.AppCompat.Light
instead of
Theme.AppCompat.Light.DarkActionBar
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
and add this theme to manifest
<application
android:name="com.qwesys.ecommerce.application.AppController"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/MyMaterialTheme">
First off, I'm not completely sure that Title Bar and Action Bar are the same? 2 different things?
Yes these are 2 different things implementation wise. Action Bar is now deprecated and we use something called the toolbar.
https://developer.android.com/reference/android/widget/Toolbar.html
You can make customized toolbar https://developer.android.com/training/appbar/setting-up.html
And for your second part use startActivityForResult() and like suggested by #sagar above you use the theme to to make the toolbar appear.
i have set these two lines of code to display both logo and app name in action bar, but only app name appears, like in the screenshot:
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setLogo(R.drawable.icon);
Do i need other code to show both? I have added this in manifest but same result:
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:logo="#drawable/icon"
I'm working on a Tabbed activity with action bar.
Can you help me? Thank you
Solved adding
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.icona);
getSupportActionBar().setDisplayUseLogoEnabled(true);
Using logo in actionbar is disabled by default in Android 5.0 Lollipop.
Add these 3 lines in the onCreate(Bundle) method of your Activity class:
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher4);
getSupportActionBar().setDisplayUseLogoEnabled(true);
Try this one in your style.xml:
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:icon">#drawable/logo</item>
<item name="logo">#drawable/logo</item>
<item name="displayOptions">useLogo|showHome|showTitle</item>
</style>
Don't know whether this makes problems with high api levels but worked for me on API 10.
Did you run you app in emulator or real device? I think on the Design page in the fragment does not show the icon of the app when using the layout of API L or 21.(as show below)
But when you change to API 19 or inflate the fragment into tap, it shows.(as show below)
I've just modified our code to use the new SupportActionBar provided in the v7-appcompat library but when running the code on a Jellybean phone (presumably the same problem exists for Honeycomb and Ice Cream Sandwich) the home button doesn't ever seem to be activated.
Calling getSupportActionBar().setHomeButtonEnabled(true); doesn't seem to do what it says but works for Gingerbread phones.
If I replace it with getActionBar().setHomeButtonEnabled(true) it does work.
The theme that I use for v11+ is as follows:
<style name="MyTheme" parent="#style/Theme.AppCompat">
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
<item name="android:listViewStyle">#style/MyListView</item>
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden</item>
<item name="android:buttonStyle">#style/MyButton</item>
<item name="android:radioButtonStyle">#style/MyRadioButtonStyle</item>
<item name="android:windowContentOverlay">#drawable/ab_solid_dove_grey</item>
<item name="android:windowTitleSize">#dimen/action_bar_height</item>
<item name="android:selectableItemBackground">#drawable/sel_standard_item</item>
<item name="android:windowBackground">#drawable/default_bg</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarText</item>
<item name="android:actionMenuTextColor">#color/gallery</item>
<item name="android:tabWidgetStyle">#style/MyTabWidget</item>
</style>
And the action bar style v11+ is defined:
<style name="MyActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">useLogo|showHome|showCustom</item>
<item name="displayOptions">useLogo|showHome|showCustom</item>
<item name="android:actionBarSize">#dimen/action_bar_height</item>
<item name="android:icon">#drawable/ic_launcher</item>
<item name="android:background">#android:color/transparent</item> <!-- Remove blue line from bottom of action bar -->
</style>
Anyone know why the home button is not getting enabled when on an Android version that supports action bar correctly.
=== UPDATE ===
I've just looked at the source code for the appcompat library and I've noticed the following in ActionBarImplBase which looks wrong to me:
setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);
This means that the home button will only be enabled if the Android version is less than ICS or if I've enabled the up indicator? - which I don't want.
This one worked for me:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_your_activity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// ... other stuff
}
#Override
public boolean onSupportNavigateUp(){
finish();
// or call onBackPressed()
return true;
}
The method onSupportNavigateUp() is called when you use the back button in the SupportActionBar.
Have you tried using all three of these (also try swapping for getSupportActionbar())?
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
Have you tried handling the button manually?
#Override
public boolean onOptionsItemSelected(int featureId, MenuItem item) {
int itemId = item.getItemId();
if(itemId == android.R.id.home){
// Do stuff
}
return true;
}
Try use Sherlock library for android devices such as Gingerbread cos android action bars is only supported from 3.0 upwards so the sherlock lock library gives you backward compatibility.
http://actionbarsherlock.com/ --- download library here.
Then add this lines in your code.
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(android.R.color.transparent);
actionBar.setDisplayUseLogoEnabled(false);
This would help you to add a back home key in your action bar. It would also make your icon invisible if you dont want it to show.
But if you want your app icon show on all activity simply comment this line below
actionBar.setIcon(android.R.color.transparent);
Now Please try this. Cause I was able to solve my own problem like this though it was on Sherlock. From your styles above I can see you did some customization to your themes. In my case I did some customization to my Sherlock theme and this was what gave me problem cos on android 4.0 and above my theme failed. so I simple added a piece of code that tells android to use the default Sherlock theme when it is running on android 4.0 and greater. So I suppose this would work for you. you tell android to use the default theme of v7-appcompat library on the version of android that is not working for you.
Code is below:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
this.setTheme(R.style.Theme_Sherlock);
} else {
this.setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);
}
In your case edit the theme to v7-appcompat library.
Please Mark as answer if it work for you. I believe it might be possible to customize the theme from the code for places were you are using this.
You can add an ActionBar to your activity when running on API level 7 or higher by extending ActionBarActivity class for your activity and setting the activity theme to Theme.AppCompat or a similar theme.
I would like to use the default Android Theme.Light in one my activities.
However, when this particular theme is applied in my application Manifest file for the selected activity:
android:theme="#android:style/Theme.Light">
it hides the activity Action Bar.
What needs to be done in java or xml code to preserve the Action Bar, using this particular Light scheme ?
As an alternative, I have used the following default scheme:
android:theme="#android:style/Theme.DeviceDefault.Light">
That scheme does show the activity Action Bar correctly, however some of its objects are not displayed as preferred. In particular, my preference would be to display buttons and spinners as per Theme.Light, but preserve the other style formatting offered by the Theme.DeviceDefault.Light
I would greatly appreciate some tips on how to achieve the above scheme formatting preferences. (I am using SDK = 16).
Why not use "android:style/Theme.Holo.Light" ? is the same but has actionbar it was added in the newer apis
I think you should use Holo.Ligt theme. The old android Theme.Light is not even aware of action bar.
I have the same problem, I like Theme.light's controls, I resolved it like this:
1) define "Theme.Light.ActionBar" in project's styles :
<style name="Theme.Light.ActionBar" parent="#android:style/Theme.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
</style>
2) in the manifest use it :
<activity
android:name="com.your.Activity"
android:theme="#style/Theme.Light.ActionBar" >
I hope that may help
I was using this xml style:
<style name="Theme.Transparent" parent="#android:style/Theme.Translucent.NoTitleBar">
This was showing a tansparent layout with full screen, no title bar or status bar on the top in android 2.1 and 2.2.
However, when I tested the application on 2.3, the same activity was showing the home screen status bar on the top (battery etc).
I had to enter these lines to my java code onCreate:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
To get it to remove any status or title bar from the top.
Can anybody shed light why this difference between 2.2 and 2.3?
You can set the theme to:
<style name="Theme.Transparent" parent="#android:style/Theme.Translucent.NoTitleBar.Fullscreen">"
And that should hide both the title bar and fullscreen in every version.
You Can Also Use This
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">