Toolbar bug with method setTitle - android

I am using this two methods in my toolbar:
toolbar.setTitleTextColor(getResources().getColor(R.color.ColorPrimary));
getSupportActionBar().setTitle("title");
The reason for using getSupportActionBar is because toolbar.setTitle("title"); is not working.
This is a bug?

It is the correct behavior.
You can find more info here.
Check the Chris Banes answer. Chris is working on the Android support libraries at Google.
So we've decided that the current behavior is correct. Once you call setSupportActionBar(Toolbar), the Action Bar is then responsible for handling the title, meaning that you need to call getSupportActionBar().setTitle(...) to set a custom title.
Then use:
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("My title");

Related

How to realise Android Components Material Design in https://material.io ? I can't find the demo

I'm focusing on Material design realization on Android and I find there are many awesome transactions and animations in https://material.io. Such as: A floating action button transforming into a toolbar
I know the transactions and animations is realised based on FabActionButton(or the newly v7 widget, ButtonNavigationView ) but I can'd find the official demos!
Thanks in advance.
Try out Chris Banes's Cheesesquare Sample
It shows some of the important features in the Design library:
Collapsing Toolbar
FloatingActionButton
View anchoring
NavigationView
Snackbar

How could I set up an app.compat actionbar toolbar without extending actionbaractivity?

I am already extending another class (expandablelistactivity) but I need a toolbar in my activity. Is there a way around this?
Usually I use toolbar in combination with:
setSupportActionbar()
in my activity. And in the xml for my activity, I'll use:
<android.support.v7.widget.Toolbar/>
And in my apptheme, I'll set it to no actionbar as so:
parent="Theme.AppCompat.Light.NoActionBar"
Folks are suggesting that I
import android.support.v7.app.AppCompatDelegate;
However, it says won't be resolved ("cannot resolve appcompatdelegate"). I have updated my Android Support Repository and Android Support Libraries.
You can use AppCompatDelegate with matching activity lifecycle callbacks for anything related to action bar.
From Chris Banes' blog:
There is a contract to maintain when you create a delegate. You must
callback to it at every call it exposes (for instance onCreate()), but
it’s really simple and can be extracted into a base class.
The end result is that you can attach all of AppCompat’s functionality
to any Activity sub-class, as long as you call it as it wants.
Check out this example of AppCompatPreferenceActivity, extending the no action bar PreferenceActivity, and using AppCompatDelegate to provide action bar.
The 22.1 release of the v4 support library offers the new AppCompatDelegate. AppCompatDelegate now exposes methods like setSupportActionbar() that before were part of ActionBarActivity.
Here is the blog post from Google where AppCompatDelegate is introduced if you need more information.

How can i remove default TITLE Bar in th android application?

Am new to this tech.
I am trying to build an application,in that i want to Remove default Title bar,and want to add my customised title bar.
Thanks in advance
It's called ActionBar in android. To remove it completely, you have to use a theme which doesn't contain ActionBar like Theme.NoTitleBar or Theme.AppCompat.NoActionBar if you're using AppCompat support library.
You need a custom ActionBar to achieve this.
Please consider reading this training and also this tutorial

ActionBarCompat: Set Navigation Mode

I'm using ActionBarCompat in my project.
The problem I have now is that I need a spinner to show in the actionbar. A standard ActionBar can use .setNavigationMode(ActionBar.NAVIGATION_MODE_LIST) but this is unavailable in the action bar compat code.
Is there a way around this? What are other options (besides a layout redesign.)
There is no way to do this in the code provided by ActionBarCompat.
It provides an ActionBar in it's most basic form for use by all platforms.
A better alternative is useing ActionBarSherlock. The setup very similar and more functionality is available out of the box.
http://actionbarsherlock.com/

Actionbar Sherlock: Setting and hiding title bar

I'm new to ActionBarSherlock, and am having two problems:
First, I just want to be able to set the title of the action bar, but it doesn't work when I call it like this:
final ActionBar actionBar = (ActionBar) findViewById(R.id.actionBar);
actionBar.setTitle("test title");
Where the corresponding xml object looks like this:
<com.myapp.prototype.ActionBar
android:id="#+id/actionBar2"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
(This is modeled after the github example: https://github.com/johannilsson/android-actionbar/blob/master/actionbarexample/src/com/markupartist/android/actionbar/example/HomeActivity.java). In other places on the web, I see reference to getSupportActionBar(), but I'm not clear how or where to call this.
Second, in another place I just want to be able to hide the Activity's title bar altogether. I'm trying to do this by calling:
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
but I can't even get this to compile. The error I'm getting is:
"The method setDisplayShowTitleEnabled(boolean) is undefined for the type
ActionBar."
In both cases, I guess the Actionbar Sherlock overrides are involved in the problem. Any suggestions how to make this work?
Thanks very much.
Setting the ActionBar title
setTitle("Title")
Hiding and showing the ActionBar
getSupportActionBar().hide();
getSupportActionBar().show();
You seem to be mixing up two different ActionBar implementations. ActionBarSherlock is an extension of the compatibility library provided by Google. The methods used with ActionBarSherlock are almost identical to the native ActionBar found in Android 3.0+ http://actionbarsherlock.com/
The Github link provided (and code you are using) is a custom implementation of an actionbar https://github.com/johannilsson/android-actionbar.
I would advise you use ActionBar sherlock and follow the usage guide here http://actionbarsherlock.com/usage.html
There is also an ActionBarSherlock getting started video here http://www.youtube.com/watch?feature=player_embedded&v=4GJ6yY1lNNY
You need to import com.actionbarsherlock.view.Window so that it secretly uses the long version of this method.

Categories

Resources