Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 使用工具栏作为操作栏不会使菜单膨胀大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用工具栏作为操作栏,我遵循Chris Banes指南:

https://chris.banes.me/2014/10/17/appcompat-v21/

现在遵循该设置我有一个空的工具栏,似乎getMenuInflater().inflate()不起作用.

在我的活动中,我:

@Override
    public Boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menuhome,menu);
        [...]

并在onCreate()中:

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://scheR_746_11845@as.android.com/apk/res/android"
    xmlns:allmyTv="http://scheR_746_11845@as.android.com/apk/res-auto"
    xmlns:ads="http://scheR_746_11845@as.android.com/apk/lib/com.google.ads"
    android:id="@+id/linearlayoutmain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <android.support.v7.widget.Toolbar
        xmlns:allmyTv="http://scheR_746_11845@as.android.com/apk/res-auto"
        android:id="@+id/my_awesome_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:BACkground="?attr/colorPriMary" />

    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="48dip"
        allmyTv:pstsInDicatorColor="#f57c1d" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </android.support.v4.view.ViewPager>


</LinearLayout>

哪里我错了?

解决方法

要将工具栏用作操作栏,您需要将属性windowActionBar设置为false.

在styles.xml中包含以下@L_197_5@

<style name="AppCompatTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="windowActionBar">false</item> 
        <item name="colorPriMary">#4285F6</item>
    </style>

标签下的manifest.xml中使用上面的主题

android:theme="@style/AppCompatTheme"

我用工具栏来夸大菜单

toolbar.inflateMenu(R.menu.your_toolbar_menu);

大佬总结

以上是大佬教程为你收集整理的android – 使用工具栏作为操作栏不会使菜单膨胀全部内容,希望文章能够帮你解决android – 使用工具栏作为操作栏不会使菜单膨胀所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。