[英]Android ToolBar icon positioning
I am trying to recreate this menu setup in Android: 我正在尝试在Android中重新创建此菜单设置:
But I can only get this: 但是我只能得到这个:
I can't seem to get rid of the WebBrowser text in the toolbar without the app crashing. 在应用崩溃的情况下,我似乎无法摆脱工具栏中的WebBrowser文本。 Additionally I can't space out the icons. 另外,我无法将图标隔开。
There is a small Progress bar between the forward and back buttons. 前进和后退按钮之间有一个小的进度栏。
Any help? 有什么帮助吗?
Here is my menu_main.xml 这是我的menu_main.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="net.txisystems.txiwebbrowser.MainActivity">
<item
android:id="@+id/action_home"
android:icon="@drawable/ic_house"
android:menuCategory="secondary"
android:orderInCategory="1"
android:title="@string/action_refresh"
app:showAsAction="always" />
<item
android:id="@+id/action_back"
android:icon="@drawable/ic_back"
android:menuCategory="secondary"
android:orderInCategory="2"
android:title="@string/action_refresh"
app:showAsAction="always" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<item
android:id="@+id/action_forward"
android:icon="@drawable/ic_forward"
android:menuCategory="secondary"
android:orderInCategory="3"
android:title="@string/action_refresh"
app:showAsAction="always" />
<item
android:id="@+id/action_refresh"
android:icon="@drawable/ic_refresh"
android:menuCategory="secondary"
android:orderInCategory="4"
android:title="@string/action_refresh"
app:showAsAction="always" />
</menu>
Placing the progress bar in my activity_main.xml under the toolbar I get this: 将进度条放在工具栏下的activity_main.xml中,我得到以下信息:
Here is the activity_main.xml code: 这是activity_main.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="net.txisystems.webbrowser.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<ProgressBar
android:indeterminate="true"
android:visibility="visible"
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
To remove title use in your activity/fragment 删除标题用于您的活动/片段
toolbar.setTitle(null)
You cannot put progressbar into menu.xml file 您不能将progressbar放入menu.xml文件
Use RelativeLayout inside Toolbar and put all views you need there like this: 在工具栏中使用RelativeLayout,然后将所需的所有视图放在此处,如下所示:
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:elevation="4dp" android:layout_width="match_parent" app:layout_scrollFlags="scroll|enterAlways" android:layout_height="?attr/actionBarSize" android:background="@drawable/gradient" app:popupTheme="@style/AppTheme.PopupOverlay"> <ProgressBar android:indeterminate="true" android:visibility="invisible" android:id="@+id/toolbar_progress_bar" android:layout_width="28dp" android:layout_marginRight="16dp" android:layout_height="28dp" android:indeterminateTint="#fff" android:indeterminateTintMode="src_in" android:layout_gravity="right" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.