本文介绍了我怎样才能把一个进度条,在工具栏的吧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着新的棒棒糖API,我们必须使用一个工具栏,如果我们想要个性化操作栏中的方面。

With the new Lollipop API, we have to use a Toolbar if we want to personalize the action bar aspect.

添加进度条到工具栏很简单,只要将它添加到工具栏的ViewGroup,克里斯·巴内斯说

Adding a ProgressBar to the Toolbar is as simple as adding it to the Toolbar ViewGroup, 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>

但如何才能将其放置在工具栏,它所属的吧?

But how can we place it at the right of the Toolbar, where it belongs?

layout_gravity 属性似乎不会为工具栏定义。从XML设置它没有任何效果。我试图改变进度条的宽度,但没有成功。

The layout_gravity attribute seems to not be defined for the Toolbar. Setting it from the xml has no effect.I tried to change the width of the ProgressBar, with no success.

我该怎么办?

修改:有一个的程序化地解决了这个问题,请参阅@mdelolmo该答复

EDIT: There is a programmatical solution to this problem, see @mdelolmo reply for that.

推荐答案

您可以试试这个。它为我工作。这里的关键是定义 layout_gravity 中的xml:安卓layout_gravity =正确的

You can try this. It worked for me. Key here is to define layout_gravity in the xml: android:layout_gravity="right"

<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:layout_gravity="right"
/>

</android.support.v7.widget.Toolbar>

这篇关于我怎样才能把一个进度条,在工具栏的吧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:44
查看更多