Android ActionBar logo doesn't display - android

I implemented a theme for my ActionBar:
<style name="MyTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/actionbar_background</item>
<item name="android:displayOptions">useLogo|showHome</item>
<item name="android:logo">#mipmap/ic_launcher</item>
<item name="logo">#mipmap/ic_launcher</item>
<item name="background">#color/actionbar_background</item>
</style>
And I applied it in AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme">
...
I know that my theme works as I see a color change, however my actionbar icon never shows up. I see it only when I explicitly call this code in onCreate method of my activity:
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.mipmap.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
I feel like it's not correct to copy-paste the same code for every activity. Please help me to solve this problem.

The new compat library doesn't use logos nor app icons in the Toolbar (former ActionBar). You should check the style guides about that: https://www.google.com/design/spec/layout/structure.html#structure-toolbars
Starting with lollipop you get new features like tinting the notification bar on this screen:
A cool new feature is that tinting which can color all ui elements like you need it for your branding.

It is better to use android.support.v7.widget.Toolbar , you can setup your app's action bar as follows:
Toolbar toolbar = (Toolbar) findViewById(R.id.apptoolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.your_app_logo);
for more info you can read at Structure Of App Bar(which was called as ActionBar)

Related

Show the ImageView behind the Appcompat ActionBar

I am using theme as:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
I want to show the ImageView partly behind the the ActionBar. I have tried Show ImageView partly behind transparent ActionBar and searched on google, but can't find the appropriate solution.
Better use Toolbar or Support Toolbar
With Toolbar, you can add it in your XML File just like any other View.
In your Activitys onCreate call setActionBar(toolbar) / setSupportActionBar(toolbar)
Or try to add these two lines in your style:
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
But using the Toolbar is actually pretty simple and the new standard.
Read this to get started: http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html

Action bar icon doesn't show icon

I'm trying to display a custom icon in the ActionBar, but it doesn't work.
I've tried it both programmatically with
getSupportActionBar().setIcon(R.drawable.forum_logo);
and
getSupportActionBar().setLogo(R.drawable.forum_logo);
and in AndroidManifest.xml with
android:logo="#drawable/forum_logo"
However, none of the two works. forum_logo.png is an image file of 24x24.
Other methods such as
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle((currentSubforum.getTitle()));
works as intended.
I'm using android.support.v7.app.ActionBarActivity and each Activity extends ActionBarActivity.
The android:icon attribute in AndroidManifest is already linked at a different drawable and the android:theme is "Theme.AppCompat.Light.DarkActionBar"
The answer with the Toolbar was correct, however was missing one crucial detail.
If you use a Toolbar, your theme must have the ActionBar disabled. There's a specific theme for that:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
Now in your onCreate set the Toolbar like this:
Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
toolbar.setLogo(R.drawable.ic_launcher);
setSupportActionBar(toolbar);
Note that you should use the support Toolbar: import android.support.v7.widget.Toolbar;
The Toolbar in your layout would look like this:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="#40ffffff"/>
That being said, I found it really weird not being able to display the app icon with ActionBarActivity. Hopefully there's another way around this.
After Fragment.onActivityCreated(...) you'll have a valid activity accessible through getActivity(). You'll need to cast it to an ActionBarActivity then make the call to getSupportActionBar().
((ActionBarActivity)getActivity()).getSupportActionBar().setSubtitle(R.string.subtitle);
You do need the cast. It's not poor design it's backwards compatibility.
in the manifest use your costume theme.
<application
android:name="com.example.ifis.MyApplication"
android:allowBackup="true"
android:icon="#drawable/ifis_logo"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
customize your theme in the style folder as below and add your icon to the icon
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/ifisGreen</item>
<item name="android:icon">#drawable/your_logo</item>
<item name="android:textColor">#color/ifisGreen</item>
<item name="android:height">30dp</item>
</style>
ActionBar actionBar = getActionBar();
actionBar.setIcon(R.drawable.ic_action_video);
actionBar.setDisplayShowTitleEnabled(true);
Only use 3 things..

Android customize AppCompat ActionBar

I have seen multiple threads on this but I am unable to find the solution to my problem. I want to create a custom action bar so to begin I just tried something simple like just a custom color:
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
Then in my Manifest I have:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
My MainActivity also extends ActionBarActivity
I was getting an error saying that I need to apply Theme.AppCompat to my Activity but I am no longer getting that error. My application compiles and runs but the action bar is just standard black, not red (#FF0000).
Eventually I want to make my action bar transparent but I figured I would get this sorted out first. Any help would be appreciated.
As said in the documentation, for retro-compatibility, you should use actionBarStyle along with android:actionBarStyle:
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
If you want flexibility use Toolbar instead of ActionBar. I dont think you can make the default action bar transpatent, and you can achieve that with Toolbar. Read more here http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html
With new AppCompat-v7 (v21) ActionBar style's properties need to refer to the app namespace, that is without android: prefix.

how to hide android logo from actionbar

I'm using navigation drawer in my application. I want to get rid of the android's robot icon from the action bar. I'm using the following lines but the logo is not disappearing.
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
Can anyone suggest me what should I do?
getActionBar().setLogo(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
Works as well.
Just add this to your activity
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
to hide the logo add below line also
actionBar.setDisplayShowHomeEnabled(false);
See this link also Android remove app icon action bar
This will done the magic:
1.) Add the following lines into your styles.xml:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
</style>
...
2.) And don't forget to add your style into your AndroidManifest.xml (if you haven't already done it):
<application
android:theme="#style/AppTheme"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
...
Hope this helps!

How do you remove the title text from the Android ActionBar?

I'm looking through the Holo.Light theme, and I can't seem to find the magic style to override to get rid of the title text that briefly shows up when my app first launches.
How can I do that?
Try:
getActionBar().setDisplayShowTitleEnabled(false);
For v.7:
getSupportActionBar().setDisplayShowTitleEnabled(false);
I think this is the right answer:
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions">showHome|useLogo</item>
<item name="displayOptions">showHome|useLogo</item>
</style>
I'm very new to Android so correct me if I'm wrong, but I think if you decide to use navigation tabs on the Action Bar, they seemed to not be completely left aligned because the title text color is only transparent and hasn't gone away.
<style name="CustomActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">useLogo|showHome</item>
</style>
worked for me.
Got it. You have to override
android:actionBarStyle
and then in your custom style you have to override
android:titleTextStyle
Here's a sample.
In my themes.xml:
<style name="CustomActionBar" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/CustomActionBarStyle</item>
</style>
And in my styles.xml:
<style name="CustomActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/NoTitleText</item>
<item name="android:subtitleTextStyle">#style/NoTitleText</item>
</style>
<style name="NoTitleText">
<item name="android:textSize">0sp</item>
<item name="android:textColor">#00000000</item>
</style>
I'm not sure why setting the textSize to zero didn't do the trick (it shrunk the text, but didn't make it go away), but setting the textColor to transparent works.
In your Manifest
<activity android:name=".ActivityHere"
android:label="">
Write this statement under
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowTitleEnabled(false);
if extending AppCompactActivity use getSupportActionbar() if extending Activity use getActionBar() else it may give
null pointer exception
using android:label="" in AndroidManifest.xml for activity also works but your app won't appear in Recently used apps
you have two choice:
first:
getActionBar().setDisplayShowTitleEnabled(false);
If usign getActionBar() produced null pointer exception, you should use getSupportActionBar()
Second
getSupportActionBar().setTitle("your title");
or
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();
You can change the style applied to each activity, or if you only want to change the behavior for a specific activity, you can try this:
setDisplayOptions(int options, int mask) --- Set selected display
or
setDisplayOptions(int options) --- Set display options.
To display title on actionbar, set display options in onCreate()
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
To hide title on actionbar.
getSupportActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
Details here.
i use this code in App manifest
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:logo="#drawable/logo2"
android:label="#string/title_text"
android:theme="#style/Theme.Zinoostyle" >
my logo file is 200*800 pixel
and use this code in main activity.java
getActionBar().setDisplayShowTitleEnabled(false);
it will work Corectly
I tried this. This will help -
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar should be called after setSupportActionBar, thus setting the toolbar, otherwise, NullpointerException because there is no toolbar set.
Hope this helps
The only thing that really worked for me was to add:
<activity
android:name=".ActivityHere"
android:label=""
>
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();
hope this will help
If you only want to do it for one activity and perhaps even dynamically, you can also use
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);
as a workaround just add this line incase you have custom action/toolbars
this.setTitle("");
in your Activity
Use the following:
requestWindowFeature(Window.FEATURE_NO_TITLE);
While all of these are acceptable, if your activity only contains a main activity, you can edit res\values\styles.xml like so:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
I've updated parent and added the .NoActionBar property to the Light theme from Android Studios Create Blank Application Wizard.
Simply extends your java file from AppCompatActivity and do this:
ActionBar actionBar = getSupportActionBar(); // support.v7
actionBar.setTitle(" ");
In your manifest.xml page you can give address to your activity label. the address is somewhere in your values/strings.xml . then you can change the value of the tag in xml file to null.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title_main_activity"></string>
</resources>
I am new to Android so maybe I am wrong...but to solve this problem cant we just go to the manifest and remove the activity label
<activity
android:name=".Bcft"
android:screenOrientation="portrait"
**android:label="" >**
Worked for me....
I remove the default appbar and run a custom toolbar instead using Theme.AppCompat.Light.NoActionBar then add a textview or something that extend to full toolbar width using attribute layout_width=match_parent and it pushes the title out of the toolbar. If you want to do this, you must study how to make a toolbar.
ActionBar actionBar = getActionBar();
actionBar.setTitle("");

Categories

Resources