我有一个工具栏和一个导航抽屉.当我启动我的应用程序时,会创建工具栏和导航抽屉.当我单击导航抽屉中的项目时,它会启动新的片段并保留相同的工具栏.当我启动特定片段时,如何将菜单项添加到工具栏中,例如搜索,添加,编辑?我不希望它们在程序的开头,但是动态创建.此外,我如何能够单击这些按钮并让它们启动其他片段.我希望它在一个片段中,与另一个片段中的编辑按钮相比,工具栏中的编辑按钮执行特定的操作.谢谢!
Menu_toolbar:
<?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">
<item android:id="@+id/edit"
    android:orderInCategory="1"
    android:title="Edit"
    app:showAsAction="always"
    android:icon="@drawable/pencil_icon"/>
<item android:id="@+id/add"
    android:orderInCategory="1"
    android:title="Add"
    app:showAsAction="always"
    android:icon="@drawable/plus_icon"/>
工具栏:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#10a1ff"
android:title="Home"
/>
我正在试图弄清楚工具栏的展开/折叠动画是如何完成的.如果您查看Telegram应用程序设置,您将看到列表视图和工具栏.向下滚动时,工具栏会折叠,向上滚动时会展开.还有配置文件pic和FAB的动画.有人有任何线索吗?你认为他们建立了所有的动画吗?也许我错过了新API或支持库中的一些东西.
我注意到Google日历应用程序中的相同行为,当您打开Spinner时(我不认为它是一个微调器,但它看起来像):工具栏展开,当您向上滚动时,它会崩溃.
只是为了澄清:我不需要QuickReturn方法.我知道可能Telegram应用程序正在使用类似的东西.我需要的确切方法是Google日历应用效果.我试过了
android:animateLayoutChanges="true"
并且expand方法运行良好.但显然,如果我向上滚动ListView,工具栏不会崩溃.
我也想过添加一个,GestureListener但我想知道是否有任何API或更简单的方法来实现这一点.
如果没有,我想我会跟着GestureListener.希望能有一个平滑的动画效果.
谢谢!
android android-animation android-toolbar android-6.0-marshmallow android-7.0-nougat
我正在寻找一种方法来使用Drawer/DrawerToggle显示汉堡图标whitout并使用Android中包含的默认图标

通过设置getSupportActionBar().setDisplayHomeAsUpEnabled(true);它显示后退箭头而不是hambuerger.Stackoverflow上的其他帖子(像这样或者这样)使用DrawerLayout或自定义drawable.我在Android源上找不到汉堡图标的矢量或png.
你知道如何在android/support库中找到原始的汉堡包图标吗?(或如何显示)
注意:可以在google.com/design网站上找到Vector和png: http ://www.google.com/design/spec/resources/sticker-sheets-icons.html#
在我的活动中
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.d(LOG_TAG, "navigation clicked");
    }
});
布局文件
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
Styles.xml
<!-- Base application theme. -->
<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primaryDef</item>
    <item name="colorPrimaryDark">@color/primaryDarkDef</item>
    <item name="colorAccent">@color/primaryDef</item>
    <!-- Remove the actionbar shadow-->
    <item name="android:windowContentOverlay">@null</item>
</style>
android android-support-library material-design android-toolbar
这是自我问答帖 我有透明的ActionBar覆盖布局.迁移到最新的支持库后,我被迫摆脱了ActionBar,转而使用工具栏.使其透明并覆盖该布局的旧方法不再适用.
<style name="CustomActionBarTheme" parent="@android:style/Theme.AppCompat">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/TransparentActionBar</item>
</style>
<style name="TransparentActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@android:color/transparent</item>
</style>
使用最后一个android.support.v7.widget.Toolbar我想在工具栏中居中一个图像,但它一直停留在左边.
对我来说最好的方法是使用toolbar.setLogo()方法并使徽标居中,但我看不到任何方法.
我使用的布局Toolbar:
  <android.support.v7.widget.Toolbar style="@style/ToolBarStyle"
                                   xmlns:android="http://schemas.android.com/apk/res/android"
                                   android:layout_width="match_parent"
                                   android:layout_height="wrap_content"
                                   android:background="?attr/colorPrimary"
                                   android:minHeight="@dimen/abc_action_bar_default_height_material">
</android.support.v7.widget.Toolbar>
是否有可能在工具栏中添加图像(徽标)并使其居中?以编程方式或在布局中?
我正在尝试新的工具栏组件,并在导航图标上遇到一些问题.我想为后台导航实现自定义图标:
在我的清单中,我将父母设置为我的活动:
<activity android:name=".CardsActivity" android:parentActivityName=".MainActivity">
    <!-- Parent activity meta-data to support API level 7+ -->
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity" />
</activity>
我声明工具栏是这样的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.lollitest.MainActivity" >
    <android.support.v7.widget.Toolbar
        android:id="@+id/my_awesome_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:layout_marginBottom="10dp"
        android:background="?attr/colorPrimary" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/my_awesome_toolbar"
        android:text="@string/hello_world" />
</RelativeLayout>
然后在我的活动中我配置工具栏如下:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
toolbar.setNavigationIcon(R.drawable.ic_good);
toolbar.setTitle("Title");
toolbar.setSubtitle("Sub");
toolbar.setLogo(R.drawable.ic_launcher);
setSupportActionBar(toolbar);
哪个给我: 

后面的图标不是我设置的图标setNavigationIcon()!无论我为方法提供什么样的绘图,导航图标始终是后退箭头.
我试图删除清单中的父关联,但唯一的效果是(显然)阻止按钮返回.
相反,如果我想要默认的后退箭头图标而不打电话setNavigationIcon()我根本没有任何图标.
处理工具栏中的导航图标(自定义和默认)的正确方法是什么?
NOte:我在Android 4.4上运行我的测试
android android-appcompat android-actionbar-compat material-design android-toolbar

我制作了一个ToolBar,但是当我在menu.xml中添加菜单项时,它总是显示为溢出.如何单独添加?此外,标题显示在中间(垂直),如何在顶部显示?
menu.xml文件
<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="com.example.toolbar.MainActivity" >
       <item android:id="@+id/action_search"
          android:icon="@drawable/ic_launcher"
          android:title="@string/action_search"
          android:showAsAction="ifRoom"
          android:orderInCategory="1" 
          android:menuCategory="secondary"/>
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>
</menu>
MainActivity.java
package com.example.toolbar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
        setSupportActionBar(toolbar);
       // toolbar.setNavigationIcon(R.drawable.back);
        toolbar.setLogo(R.drawable.ic_launcher);
        //toolbar.setTitle("Title");
       // toolbar.setSubtitle("Subtitle");
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it …我试图让导航抽屉在工具栏下面打开.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
tools:context=".MainActivity">
<RelativeLayout
    android:layout_width = "match_parent"
    android:layout_height = "wrap_content">
    <include layout="@layout/toolbar"
        android:id="@+id/toolbar"/>
    <FrameLayout
        android:layout_below="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_color"/>
</RelativeLayout>
<ListView
    android:id="@+id/drawer"
    android:layout_width="260dp"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar"
    android:layout_marginTop="56dp"
    android:layout_gravity="start">
</ListView>
</android.support.v4.widget.DrawerLayout>
如何重新格式化xml以便导航栏在工具栏下方打开?
我正在尝试使用CoordinatorLayout关注Google文档,但我在CoordinatorLayout中遇到了ScrollView的问题.基本上,当向下滚动时,工具栏通常会使用RecyclerView或Listview折叠.现在使用ScrollView它不会崩溃.
<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >
        <TextView
            android:id="@+id/tv_View"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="@string/filler"
            style="@style/TextAppearance.AppCompat.Large"
            />
    </ScrollView>
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            />
    </android.support.design.widget.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>
android toolbar android-scrollview android-toolbar coordinator-layout
以下是Google Maps Toolbar的屏幕截图.

如您所见,图标左对齐而不是右对齐(默认行为).我已经尝试将android:layout_gravity ="left"和android:gravity ="left"添加到工具栏但它无法正常工作.还尝试将内部LinearLayout(具有相同的重力值)添加到工具栏但是也没有工作.有任何想法吗?我希望能够在工具栏小部件中使用常规Android菜单,而不是从头开始重新创建所有内容.
android toolbar android-layout android-5.0-lollipop android-toolbar