Android change "up" button image - android

I am creating an Android application with custom navigation bar.
My current navigation bar looks like this:
I would like to create a navigation bar like this:
To create a navigation bar like this, at first I need to change default Android "up" button. To achieve this In developers forums I have found a way:
<style name="MyCustomTheme" parent="Theme.AppCompat.Light">
<item name="android:homeAsUpIndicator">#drawable/custom_up_button</item>
</style>
And set this theme in AndroidManifest.xml:
<activity
android:name=".LoginActivity"
android:theme="#style/MyCustomTheme"
android:label="LOGIN" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mycompany.HomeActivity" />
</activity>
Sadly, this doesn't change my "up" button. I must be doing something wrong. Does anyone know what?

You can change it programmatically like this:
-Add your drawable into the folder
-Create an object Action bar and change it like this:
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
ab.setHomeButtonEnabled(true);
ab.setHomeAsUpIndicator(R.drawable.yourDrawable);
and it works.

Change it programmatically with:
Drawable upArrow = ContextCompat.getDrawable(getApplicationContext(), R.drawable.custom_up_button);
getSupportActionBar().setHomeAsUpIndicator(upArrow);

Related

Activity with no Title/Action bar

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.

How to hide app name from title bar in Android?

My app is showing name and icon. I want to hide name.
How i can do that?
You have to call `
getSupportActionBar().setDisplayShowTitleEnabled(false) - to hide it,
or
getSupportActionBar().setTitle("new title"); - if you want to change it
Kinda "workaround", but it's working fine:
In the Manifest
<activity
android:name=".YourActivity"
android:label="" />
You can use getSupportActionBar.
if you want to hide just your app name use this code in Activity of that page :
getSupportActionBar().setDisplayShowHomeEnabled(false);
And if you want to hide ActionBar use this
getSupportActionBar().hide();
And you can ReName your app with :
getSupportActionBar().setTitle("that name you want");
Totaly you can use:
getSupportActionBar().
and others code ...
If you want to do this outside of the code, put this in your manifest:
<activity android:name=".ActivityName"
android:theme="#android:style/Theme.NoTitleBar">
edit: ranjith beat me to it.
It works for me
Go to Style.xml change it from
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
In Kotlin you can use:
supportActionBar?.setDisplayShowTitleEnabled(false)
The "?" is important because you can have the whole title bar disabled already because you try to set a a not existing title bar's title status to false.
just replace parent property for appTheme style in styles.xml to '#android:style/Theme.NoTitleBar'

Apply color change in Action bar navigation button

I've been to the documentation, I'm still lost how to change the color on the navigation icon thing with 3 dashes near the app logo.
That "thing" is the homeasupindicator icon. You can change it in your styles.xml file, by customizing your Theme, modifying the android:homeAsUpIndicator attribute.
In your Manifest.xml you can define your Theme for your whole application, or for each of your Activities.
So, add a style to your styles.xml, like this:
<style name="Theme.MyCustomTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">#drawable/my_indicator_drawable</item>
Then, on your Manifest.xml, do:
android:theme="#style/Theme.MyCustomTheme"
This will override the icon on the ActionBar.
Don't forget to call getSupportActionBar().setDisplayHomeAsUpEnabled(true); to activate the icon behaviour.

Remove icon/logo from action bar on android

I've been trying to find some way of removing the icon/logo from the action bar but the only thing I've found after an hour of searching SO, Android's documentation and Google is how to remove the title bar in whole. That is not what I want. Only want to remove the icon/logo from the title bar.
Any one know how to accomplish this? Preferably I'd like to do this in XML.
Add the following code in your action bar styles:
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item> <!-- This does the magic! -->
PS: I'm using Actionbar Sherlock and this works just fine.
If you do not want the icon in particular activity.
getActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));
If you've defined android:logo="..." in the <application> tag of your AndroidManifest.xml, then you need to use this stuff to hide the icon:
pre-v11 theme
<item name="logo">#android:color/transparent</item>
v11 and up theme
<item name="android:logo">#android:color/transparent</item>
The use of these two styles has properly hidden the action bar icon on a 2.3 and a 4.4 device for me (this app uses AppCompat).
This worked for me
getActionBar().setDisplayShowHomeEnabled(false);
Calling
mActionBar.setDisplayHomeAsUpEnabled(true);
in addition to,
mActionBar.setDisplayShowHomeEnabled(false);
will hide the logo but display the Home As Up icon. :)
Be aware that:
<item name="android:icon">#android:color/transparent</item>
Will also make your options items transparent.
//disable application icon from ActionBar
getActionBar().setDisplayShowHomeEnabled(false);
//disable application name from ActionBar
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setIcon(android.R.color.transparent);
This worked for me.
Remove or show the title using:
getActionBar().setDisplayShowTitleEnabled(true);
Remove or show the logo using:
getActionBar().setDisplayUseLogoEnabled(false);
Remove all:
getActionBar().setDisplayShowHomeEnabled(false);
you can also add below code in AndroidManifest.xml.
android:icon="#android:color/transparent"
It will work fine.
But I found that this gives a problem as the launcher icon also become transparent.
So I used:
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
and it worked fine.
But if you are having more than one activity and want to make the icon on an activity transparent then the previous approach will work.
I used this and it worked for me.
getActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
getActionBar().setDisplayHomeAsUpEnabled(true);
I think the exact answer is: for api 11 or higher:
getActionBar().setDisplayShowHomeEnabled(false);
otherwise:
getSupportActionBar().setDisplayShowHomeEnabled(false);
(because it need a support library.)
go to your manifest an find the application tag
android:icon="#android:color/transparent"// simply add this on place of your icon
.....
...
...
Qiqi Abaziz's answer is ok, but I still struggled for a long time getting it to work with the compatibility pack and to apply the style to the correct elements. Also, the transparency-hack is unneccessary. So here is a complete example working for v8 and up:
values\styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyActivityTheme" parent="#style/Theme.AppCompat">
<item name="actionBarStyle">#style/NoLogoActionBar</item> <!-- pre-v11-compatibility -->
<item name="android:actionBarStyle">#style/NoLogoActionBar</item>
</style>
<style name="NoLogoActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="displayOptions">showHome</item> <!-- pre-v11-compatibility -->
<item name="android:displayOptions">showHome</item>
</style>
</resources>
AndroidManifest.xml (shell)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>
<application android:theme="#android:style/Theme.Light.NoTitleBar">
<activity android:theme="#style/PentActivityTheme"/>
</application>
</manifest>
Go in your manifest and find the your activity then add this code:
android:theme="#android:style/Theme.NoTitleBar"
above line hide your Actionbar .
If you need to other feature you can see other options with (CLR + SPC).
The fastest way is to modify your Manifest.xml.
If for example you want to remove the logo of activity "Activity", and leave the logo in other activities, you can do the following:
<activity
android:name=".home.XActivity"
android:logo="#android:color/transparent"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".home.HomeActivity"
android:configChanges="orientation|keyboardHidden" />
None of the above worked.
But this did the trick:
override fun onCreate() {
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
toolbar.logo = null
(removed icon from toolbar)

How to hide the actionbar before the Activity is loaded?

My goal is to show a splash screen on my applications startup. Right now what it will do is briefly show the actionbar with an otherwise blank page, then jump to the splash screen. I'm trying to figure out how to not show the beginning screen and just start with the splash screen.
I'm trying to use these links for information on how to solve this.
ActionBar Lag in hiding title
In this one I'm assuming I can use the same type of method for hiding the actionbar by changing the theme, but I don't know what I would actually use as my style to do so.
How to hide action bar before activity is created, and then show it again?
and here it talks about adding a line to the manifest that would do it. Where in the manifest? Anywhere I put it did not do anything.
try this in manifest file
<activity
android:name="yourActivityName"
android:label="your label"
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
</activity>
Check this link Android: hide action bar while view load
Code snippets from the link, incase the link breaks down, courtesy #kleopatra:
Setting the properties windowNoTitle to true on your theme will
hide the ActionBar. use two different themes both extending parent="Theme.AppCompat.Light" in order to prevent NPE when using getSupportActionBar
set the styles as
<style name="AppThemeNoBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppThemeBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">false</item>
</style>
Due to some odd behaviour on versions < 11, you need to add
if (Build.VERSION.SDK_INT < 11){
getSupportActionBar().hide(); }
inside activities that do not need the actionbar
Delete the "android:label" entries in Manifest file, from application and the first activity which is loaded. In your case, the Splash activity.
Sample...
<application
android:allowBackup="true"
android:icon="#drawable/starticon"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo">
<activity
android:name=".ActivitySplash"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Just add this code in your Activity in the onCreate function.
val actionBar = supportActionBar?.apply{hide()}

Categories

Resources