Tag: android toolbar

video播放器使用appcompat-v7在Android中熄灭模式

我将从本机Holo( Theme.Holo等)的代码库移植到appcompat-v7 ( Theme.AppCompat等)。 如果你不想阅读详细信息,最后一部分包含tl; dr 。 问题 一切正常,但我有复制一个很容易使用旧的ActionBar行为的问题。 我有一个video播放器,在风景中,我希望它的行为像YouTube:隐藏(animation)播放器控件,应用程序栏和状态栏。 在用户交互时,UI控件应该保持这个“熄灯”模式并且回到正常状态。 如果用户在X秒钟内没有触摸屏幕,则定时器将返回熄灭模式。 使用ActionBar的相同代码不会使用Toolbar 。 所以,我使用的是: 一个不透明的状态栏 setSystemUiVisibility()使用这些组合之一: 默认: View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 熄灭: View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE minSdkVersion是16 显示和隐藏ActionBar,我简单地称它为show()和hide() 在应用程序栏上实现相同的行为我subclassed Toolbar并添加一个show()和一个hide()方法相同(首先简单地使用setVisibility() ,然后使用animation – 获得相同的结果) LAYOUT_STABLE使得appbar最终会在状态栏后面(因为它意味着一个fitSystemWindows 。由于appbar是视图层次结构中的普通视图,并不像ActionBar那样装饰,它受到那个标志这是我在屏幕上看到的: 不立即清除工具栏边界是什么,因为应用程序栏在黑暗中是黑暗的,但是您可以看到标题被剪切和“未alignment”。 这是因为工具栏大小正确,但在状态栏后面。 我的主要问题是在这一点上,没有公共的API来获得状态栏高度,矩形或其他任何东西来垂直移动我的应用程序栏以显示在状态栏下方。 testing主要是在LP513D上的N5上进行的(在编写本文时为最新的Lollipop公开构build版本),但Android 4.4上也可以看到相同的结果。 哈克解决scheme 也就是说,经过相当一段时间和一些失败的尝试,使得它以不太疯狂的方式工作(包括试图把它装进装饰的相当绝望的尝试),我采取了这种使它工作的恶劣方式: […]

如何以编程方式为工具栏设置app:layout_scrollFlags

我的应用程序有一个viewpager和4个选项卡,每个选项卡有很多片段。 但是我只想让我的工具栏滚动向上/向下滚动recyclerview在2个特定的选项卡。 但我不知道如何阻止其他选项卡的工具栏滚动。 我试图导入每个片段的工具栏,但似乎我不能这样做。 任何人有想法解决这个问题?

Android v7工具栏buttonalignment

我在我的应用中使用下面的代码添加了android.support.v7.widget.Toolbar ,现在我想在工具栏的右端显示一个button,但是不能这样做。 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/accent_color" android:minHeight="?attr/actionBarSize" android:layout_alignParentTop="true" tools:context=".MyActivity" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/showevents" android:textSize="12sp" android:background="@null" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:textColor="@color/white" android:text="UPCOMING \nEVENTS"/> </android.support.v7.widget.Toolbar> 我也添加了下面的图片,但是没有被移动到正确的位置。 android:layout_alignParentEnd="true" android:layout_alignParentRight="true" 附图供参考:

Android工具栏添加不同片段的菜单项

我有一个工具栏以及一个导航抽屉。 当我开始我的应用程序,工具栏和导航抽屉被创build。 当我点击导航抽屉中的项目时,它会启动新的碎片并保留相同的工具栏。 我如何基本上添加菜单项到工具栏,如search,添加,编辑到我的工具栏,当我启动特定的片段。 在程序开始时我不想要它们,而是dynamic创build。 另外,我将如何能够点击这些button,并让他们开始其他片段。 我想在一个片段中,工具栏中的编辑button与另一个片段中的编辑button相比,会做一些特定的事情。 谢谢! 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" />

如何在CollapsingToolbarLayout中使用带有工具栏的TabLayout?

我正在看chrisbanes / cheesesquare ,我试图把TabLayout和一个工具栏放在一个CollapsingToolbarLayout里面,这里是我的代码 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="@dimen/detail_backdrop_height" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/primary_dark" android:minHeight="150dip" app:layout_scrollFlags="scroll|exitUntilCollapsed" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginStart="48dp" app:expandedTitleMarginBottom="60dp" app:expandedTitleMarginEnd="64dp"> <ImageView android:id="@+id/backdrop" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:fitsSystemWindows="true" app:layout_collapseMode="parallax" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="110dip" android:layout_gravity="top" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:layout_collapseMode="pin" /> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" […]

在日志中看到消息:“app:theme is deprecated”?

自升级到最新的appcompat库以来,我在ViewUtils的日志中看到一条消息。 app:theme is now deprecated. Please move to using android:theme instead. 我使用parent="Theme.AppCompat.Light.NoActionBar"作为我的主题父。

工具栏图像居中

使用最后一个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> 有没有可能将图像(徽标)添加到工具栏并居中? 编程或在布局?

修复CoordinatorLayout中的底部条

我有一个CoordinatorLayout包含AppBarLayout和一个包含片段的FrameLayout 。 其中一个片段包含顶部的TabLayout ,一个TabLayout和底部的一个“自制”工具栏。 AppBarLayoutconfiguration了app:layout_scrollFlags="scroll|enterAlways" 我的问题是两个“工具栏”隐藏滚动时,AppBarLayout和我的“自制”工具栏在底部。 这是目前的行为 我想修复底部“自制”工具栏,以保持可见,但我无法实现它。 这是片段布局的XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.design.widget.TabLayout android:id="@+id/toolbarfilter" android:layout_width="match_parent" android:background="@color/azul_asde" app:tabMode="fixed" app:tabMaxWidth="0dp" android:elevation="4dp" app:tabIndicatorColor="@color/verde_pastel" android:layout_height="wrap_content" /> <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipeContainer" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <android.support.v7.widget.RecyclerView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.v4.widget.SwipeRefreshLayout> <LinearLayout android:id="@+id/toolbarselection" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingTop="10dp" android:paddingBottom="10dp" android:background="@color/azul_asde" android:elevation="4dp" android:visibility="visible" > <ImageView android:id="@+id/delete" android:layout_width="0dp" android:layout_height="wrap_content" […]

Toolbar.inflateMenu似乎什么都不做

目前,我正在将新的AppCompat库带到老设备的材料devise周围。 设置一个工具栏作为操作栏工作正常,但工具栏似乎没有做任何事情调用inflateMenu(int resId) 。 从文档,我认为这是取代getMenuInflater().inflate(int resId)从onCreateOptionsMenu调用。 如果我做后者,菜单项正确膨胀,并添加到工具栏,但inflateMenu似乎没有。 我错过了什么? 活动代码: Toolbar toolbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.inflateMenu(R.menu.main); // this does nothing at all setSupportActionBar(toolbar); } // this works @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } 提前致谢!

需要禁用展开CollapsingToolbarLayout的某些片段

我有一个控制replace很多片段的AppCompatActivity。 这是我的布局。 activity_main.xml中 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_height="match_parent" android:layout_width="match_parent" android:fitsSystemWindows="true"> <include layout="@layout/activity_main_frame"/> <android.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" android:background="@color/white" app:headerLayout="@layout/drawer_header" app:menu="@menu/drawer"/> </android.support.v4.widget.DrawerLayout> activity_main_frame.xml <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginStart="48dp" app:expandedTitleMarginEnd="64dp"> <ImageView android:id="@+id/backdrop" android:layout_width="match_parent" android:layout_height="256dp" android:scaleType="centerCrop" android:fitsSystemWindows="true" app:layout_collapseMode="parallax" /> <include layout="@layout/activity_main_items"/> […]