Tag: android toolbar

如何使用appcompat v21在独立工具栏上启用homeAsUp或调用setDisplayHomeAsUpEnabled()

我想转换我的应用程序使用v21 AppCompat库,所以我开始使用工具栏,而不是ActionBar。 在我所有的常规活动(扩展ActionBarActivity)中,一切都很好。 但在我的设置活动,它扩展了PreferenceActivity,因此我不能使用setSupportActionBar(actionbar)调用我需要使用“独立”工具栏。 工具栏显示出来,但我不知道如何添加“home / up”button到工具栏。 SettingsActivity.java: public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); Toolbar actionbar = (Toolbar) findViewById(R.id.actionbar); if (null != actionbar) { // In every other activity that extends ActionBarActivity I simply use: // setSupportActionBar(actionbar); // final ActionBar supportActionBar = getSupportActionBar(); // supportActionBar.setDisplayHomeAsUpEnabled(true); // but […]

Android棒棒糖,从工具栏中的标题添加popup式菜单

我无法看到如何在标题中添加popup式菜单,如许多材料devise示例中所示。 任何帮助将非常感激。

安卓工具栏popupTheme vs主题

我经常在布局文件中看到这个工具栏的声明: <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> </android.support.v7.widget.Toolbar> 为什么有两个关于主题的属性:theme和popupTheme? 他们每个人的目的是什么?

如何在Google地图应用中将Android工具栏菜单/图标alignment到左侧?

以下是Google地图工具栏的屏幕截图。 正如你所看到的图标是左alignment,而不是右(默认行为)。 我已经尝试添加android:layout_gravity =“左”和android:gravity =“左”到工具栏,但它没有工作。 也尝试添加一个内部的LinearLayout(具有相同的重力值)的工具栏,但也没有工作。 有任何想法吗? 我希望能够使用工具栏小部件的常规Android菜单,而不是从零开始重新创build所有的东西。

工具栏导航汉堡图标丢失

我正在寻找一种方式来显示使用抽屉/ DrawerToggle的汉堡包图标,并使用Android中包含的默认图标 通过设置getSupportActionBar().setDisplayHomeAsUpEnabled(true); 它显示后面的箭头而不是汉堡。 在Stackoverflow上的其他post(如这个或这个 )使用DrawerLayout或自定义drawable。 我找不到在Android源汉堡图标vector或PNG。 你知道我怎么能findAndroid /支持库中的原始汉堡包图标? (或如何显示它) 注意:Vector和png可以在google.com/design网站上find: 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> […]

“后退button”使用getSupportActionbar和appcompat v7工具栏

我正在使用Appcompat V7库中的新工具栏,并使用导航抽屉和碎片创build应用程序。 在一些片段中,我不想显示汉堡包图标,而是显示箭头。这很好,我是这样做的: mDrawerToggle.setDrawerIndicatorEnabled(false); mDrawerToggle.syncState(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha); 我的问题是:如何或在哪里我需要设置家庭buttonlisener或我需要听“后退”button? 我想调用主压缩方法,并设置汉堡包图标的导航抽屉图标。

我该如何修复放置在工具栏顶部的Android 4.x的微调器样式

根据Android文档 ,Spinner小部件支持Material Design样式。 所以我决定在我的应用程序中将它放在工具栏的顶部。 布局/ activity_base.xml <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:background="?attr/colorPrimary" android:elevation="5dp" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> <Spinner android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </android.support.v7.widget.Toolbar> 活动主题 <style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/omni_primary_color</item> <item name="colorPrimaryDark">@color/omni_primary_color_dark</item> <item name="colorAccent">@color/omni_accent_color</item> </style> BaseActivity.java public class BaseActivity extends ActionBarActivity { @InjectView(R.id.my_awesome_toolbar) Toolbar mToolbar; @InjectView(R.id.spinner) Spinner spinner; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base); ButterKnife.inject(this); //setup toolbar […]

我们应该用ToolBarreplaceAction Bar吗?

自从添加到Support v7库以来,我一直在使用ToolBar 。 我想我用得很好。 但有一点我不明白。 为什么Google会创build这样一个小部件? 我的意思是我们可以做任何ToolBar可以通过使用ActionBar做。 为什么我们必须使用ToolBar ? 如果有的话, ToolBar优于ActionBar ? 是否有必要通过ToolBarreplaceActionBar ? 任何提示都表示赞赏。 并提前感谢。 PS:我发现ToolBar是ViewGroup一个变种。 那么,我们怎么能像Layout一样使用ToolBar呢? 有人可以发布一些代码吗?

工具栏不会以Scrollview作为CoordinatorLayout的子项折叠

我正在尝试关注使用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>

在工具栏上显示ActionMode

我正在尝试使用新的android.support.v7.widget.Toolbar ,除了传统的android.app.ActionBar 。 我能够显示它: toolbar.startActionMode(callback); 问题是ActionMode显示在ActionBar ,而不是在Toolbar 。 有没有办法改变这个? 我尝试在我的主题中设置以下内容,但似乎没有改变任何内容: <item name="windowActionModeOverlay">true</item>