Last active
August 6, 2020 16:39
-
-
Save surajsau/940e5719a13a3916cdc4d2ada827c422 to your computer and use it in GitHub Desktop.
AOSP implementation of Toolbar.setTitle()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set the title of this toolbar. | |
* | |
* <p>A title should be used as the anchor for a section of content. It should | |
* describe or name the content being viewed.</p> | |
* | |
* @param title Title to set | |
*/ | |
public void setTitle(CharSequence title) { | |
if (!TextUtils.isEmpty(title)) { | |
if (mTitleTextView == null) { | |
final Context context = getContext(); | |
mTitleTextView = new AppCompatTextView(context); | |
mTitleTextView.setSingleLine(); | |
mTitleTextView.setEllipsize(TextUtils.TruncateAt.END); | |
if (mTitleTextAppearance != 0) { | |
mTitleTextView.setTextAppearance(context, mTitleTextAppearance); | |
} | |
if (mTitleTextColor != null) { | |
mTitleTextView.setTextColor(mTitleTextColor); | |
} | |
} | |
if (!isChildOrHidden(mTitleTextView)) { | |
addSystemView(mTitleTextView, true); | |
} | |
} else if (mTitleTextView != null && isChildOrHidden(mTitleTextView)) { | |
removeView(mTitleTextView); | |
mHiddenViews.remove(mTitleTextView); | |
} | |
if (mTitleTextView != null) { | |
mTitleTextView.setText(title); | |
} | |
mTitleText = title; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment