使用新的Lollipop API,如果我们想要个性化操作栏外观,就必须使用工具栏。
像Chris Banes所说的那样,将进度条添加到工具栏视图组中就像将其添加到工具栏视图组一样简单。as Chris Banes said。
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_green_500"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- Color is Brown 500 -->
<ProgressBar
android:id="@+id/toolbar_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="#795548"
android:indeterminateTintMode="src_in"/>
</android.support.v7.widget.Toolbar>
但是我们如何将它放置在工具栏的右侧,它应该在那里呢?
“layout_gravity”属性似乎没有为工具栏定义。从xml中设置它没有效果。我尝试更改ProgressBar的宽度,但没有成功。
我该怎么办?
编辑:这个问题有一个编程解决方案,请参见@mdelolmo的回复。