Remove App Icon from Navigation Drawer ActionBar Does not work - android

I am working on an App which has design requirement to be built as it should only have the Title on the ActionBar and not the App Icon.
i tried various solutions found from StackOverflow like
getActionBar().setDisplayUseLogoEnabled(false);
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setIcon(null);
however none of these worked so far, even i tried to make a hack/fix by making a transparent ic_launcher icon and put it into manifest.xml but it causes the App installation icon make transparent.
please help
getActionBar().setDisplayShowHomeEnabled(false);
works perfectly in 4.4 kitkat , but showing a back arrow in downgraded version like this
and i need it like this to work in every device

please try adding this..
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
and in your theme add
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item
</style>
<!-- ActionBar styles -->
<style name="ActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:icon">#android:color/transparent</item>
</style>

Its quite tricky anyhow, but i solved it,and it works like a charm in all devices.
I made a 2x2 px transparant icon and added it as
ActionBar actionBar = getActionBar();
actionBar.setIcon(R.drawable.actionbar_null_icon);
and removed the code
getActionBar().setDisplayUseLogoEnabled(false);
getActionBar().setDisplayShowHomeEnabled(false);
thanks to nDroidDev for suport

Related

App with white toolbar and dark text

I have been trying to achieve this in a project with minSDK 16 :
Actionbar and statusbar in White color with dark text and icons.
Like this:
I have been trying to figure this out for ages now. Google searches lead to a lot of answers that dont make any sense and/or dont support older api's. colorControlNormal, titleTextColor, Appcompat-this, Appcompat-that... its a nightmare!
I am also not able to find any docs on what items to put in my styles xml, and none of the combinations of style properties I tried seem to have any effect whatsoever.
So can someone please give me a proper and well explained walkthrough as to how I can acheive this effect?
Thanks.
you can try with that
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#color/white</item>
<item name="android:windowLightStatusBar">true</item>
</style>
but API min is 23.
Also, don't forget to use different styles for different versions of APIs so far I haven't found an app that works as you want, so most probably isn't possible.
Add these to your Base Application Theme in styles.xml
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
And add following attribute to your parent layout:
android:fitsSystemWindows=”true”
You can customize your toolbar with custom view as follows:
Create your view inside toolbar and use in you code as you want
XML:
<android.support.v7.widget.Toolbar>
</android.support.v7.widget.Toolbar>
Java:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
This will help you

Show both logo and app name in action bar android

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)

Navigation drawer toggle padding

I'm using appcompat v7 with the hamburger to arrow toggle.
However, I would like to add some padding on the left of the toggle.
This is my current situation :
http://nl.tinypic.com/r/2a0f712/8
This is what I would like to have :
http://nl.tinypic.com/r/v3q176/8
I've tried this :
findViewById(android.R.id.home).setPadding(25, 0, 15, 0);
But that didn't work. However, this did add padding on the right of the toggle.
I've also tried to add padding in the styles but that didn't work either.
AFAIK, the action is hard-coded in layout resources. U cant change the padding. Google did this to maintain the consistency across the app guess.
However u can define ur own icon in a drawable with ur own attributes (padding and all) and use it as an indicator by adding this line to styles.xml
<item name="android:homeAsUpIndicator">#drawable/xyz</item>
And the image u have shown about what u want is actually a toolbar and not an action bar. In toolbar, the icon is by default placed there.
To know more about toolbar and how to implement them, here is a link : http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre.html
I'm going to assume you are familiar with styling to some extent and recommend you go that route. FYI I have not confirmed the code below as working but I think it would be close to what you want.
For res/values-14/style.xml, something like this:
<!-- style for Action Bar -->
<style name="MyPaddedActionBar" parent="android:style/Widget.Holo.Light.ActionBarView">
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>
And then for everything 14 and below, you would use AppCompat (res/values-14/style.xml):
<style name="MyPaddedActionBar" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>

Android get Support Action Bar always returns NULL

I'm using the support library v7 on a certain project. I'm trying to instantiate the support action bar like this:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(R.layout.top_action_bar);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setHomeButtonEnabled(true);
Everything works fine on Android devices with API lvl below 11. However, while trying to run the same code on newer devices, like a Samsung Galaxy S4 with Android 4+, getSupportActionBar() always returns null, causing the expected crash.
I'm using this style file:
<style name="my_style" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/my_style_ab</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="my_style_ab" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:height">70dp</item>
</style>
Any hints on what may be wrong? I think it has something to do with the style, or maybe I just can't use the support ActionBar on API lvl above 11. Thanks in advance.
Using android:windowNoTitle with true is hiding your ActionBar
I got the solution. And I didn't provide enough information in the question so it may be hard for others to help. However, I don't know why the problem happens, I just found out how to solve it. The error was due to the app title. I removed this item from the style:
<item name="android:windowNoTitle">true</item>
And also all the references in the code regarding that title bar, like this one:
requestWindowFeature(Window.FEATURE_NO_TITLE);
Why does this solve it? still don't know. It may be useful for me if someone can explain it.
If you are using Toolbar and AppCompat then you probably have android:windowNoTitle set to true, hiding your action bar. Create a Toolbar in your xml and add this code in the onCreate() of your activity.
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Inside Manifest file, check the activity for which are you having the issue.
I have the theme with "NoActionBar" Property.
Removing it resolved this code worked for me.
android:theme="#style/AppTheme.NoActionBar"

How to add menu button on the navigation bar

I have a simple app which only needs a menu button with some options, and it should work in all devices.
Anyway, my app works fine in all cases, except for that I couldn't place menu button on the navigation bar.
Here is my code:
styles.xml in value folder
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
</style>
styles.xml in value-v11 & value-v14 folders
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
<item name="android:actionBarStyle">#android:style/Widget.Holo.ActionBar</item>
</style>
This code appears in all onCreate events of my activities
if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 &&
ViewConfiguration.get(this).hasPermanentMenuKey()))
{
// menu key is present
ActionBar actionBar = getActionBar();
if(actionBar!=null)
actionBar.hide();
}
else
{
//No menu key
ActionBar actionBar = getActionBar();
if(actionBar!=null)
actionBar.show();
}
This code works fine, but in case I there isn't any action bar, I want to put the menu button in the navigation bar.
I've done so much googling for that, but I couldn't find any working solution for this.
Thanks in Advance.
Since nobody had answered my question, I had to answer it my self.
First, it seems it is not recommended to activate the menu button in the navigation bar! (By Google)
Anyway, if you are interested in activating it, all you have to do is:
1. Make a simple menu like before
2. Not to use an action bar
3. Set targetSdkVersion to 13 or below
And, it is highly recommended to read this article Say Goodbye To The Menu Button

Categories

Resources