I am trying to add an animation with "makeSceneTransitionAnimation" in a Toolbar title, but like it is private, i can't to set a "transitionName" on it.
If Anybody know how resolve this or know other way help me.
Because you're using Toolbar you can consider the possibility of directly creating a custom title TextView:
Disable the default ActionBar title:
@Override
public void onCreate(Bundle savedInstanceState) {
// ...
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Either by calling
getSupportActionBar().setTitle(null);
// Or
toolbar.setTitle(null);
// Or
getSupportActionBar().setDisplayShowTitleEnabled(false);
// ...
}
there are lots of other ways of disabling the default title from XML as well, some are discussed in this question: Remove title in Toolbar in appcompat-v7.
Then in Activity's layout file add a custom title TextView inside Toolbar:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/AppTheme"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:id="@+id/custom_title"
android:text="@string/activity_title"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:transitionName="@string/title_transition_name"/>
</android.support.v7.widget.Toolbar>
textAppearance
can be used to apply the same style of the default ActionBar title.
This approach allows you to have more control over the title view, especially if you need to play some additional TextView
properties Animation
s together with your sceneTransition
and you want to be able to explicitly define the final appearance of the title.
If you prefer, the default title TextView can be found in different ways:
@Override
public void onCreate(Bundle savedInstanceState) {
// ...
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// This assumes that the title is the first child of Toolbar
TextView titleTextView = (TextView) toolbar.getChildAt(0);
// Or this assumes that the title is the first TextView inside of Toolbar
for(int i = 0; i < toolbar.getChildCount(); ++i) {
View child = toolbar.getChildAt(i);
if(view instanceof TextView) {
titleTextView = (TextView) view;
break;
}
}
}
the transitionName
can then be set:
titleTextView.setTransitionName(/* Transition name */);
more ways to find title TextView are discussed here Getting ActionBar Title TextView with AppCompat v7 r21.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With