Android Fix toolbar title does not show problems

Source: Internet
Author: User

Problem reason: Toolbar compatibility problem
Workaround:
Setsupportactionbar (toolbar);

Toolbar steps to use:

1, write Menu.xml

In order to maintain compatibility it is necessary to write:
android:showasaction= "Ifroom"
app:showasaction= "Ifroom"
Ignore as warnings

<?xml version="1.0"encoding="Utf-8"? ><menu xmlns:android="http://schemas.android.com/apk/res/android"Xmlns:app="Http://schemas.android.com/apk/res-auto"Xmlns:tools="Http://schemas.android.com/tools"Tools:context=". Mainactivity"> <Item Android:id="@+id/advertise"android:checkable="true"Android:icon="@mipmap/icon_connected"android:orderincategory=" -"Android:title="AD"android:visible="true"android:showasaction="Ifroom"app:showasaction="Ifroom"/> <Item Android:id="@+id/add_friends"android:checkable="true"Android:icon="@mipmap/ic_launcher"android:orderincategory=" -"Android:title="Add Friends"android:visible="true"android:showasaction="Ifroom"app:showasaction="Ifroom"/></menu>

2. Rewriting Oncreateoptionsmenu and Onoptionsitemselected methods

After the completion of the two steps, toolbar still does not show the need for a third step
3. Resolve compatibility issues:
Called after initializing toolbar:

Setsupportactionbar (toolbar);

Android Fix toolbar title does not show problems

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.