[英]Toolbar in android
Is there any tutorial easy to understand to create a toolbar with the home button aligned to the left and the log out button aligned to the right?是否有任何易于理解的教程来创建一个主页按钮向左对齐且注销按钮向右对齐的工具栏?
I am using menu type.xml files to do it, but I am not able to align the buttons as I want.我正在使用菜单 type.xml 文件来执行此操作,但我无法根据需要对齐按钮。
My.xml is: My.xml 是:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/etxera"
android:icon="@drawable/etxera_fondo"
android:title="Hasierara"
app:showAsAction="always" />
<item android:id="@+id/saioa_itxi"
android:icon="@drawable/saioaitxi"
android:title="saioa itxi"
app:showAsAction="ifRoom" />
</menu>
Thanks for support!谢谢你的支持!
Make a custom toolbar制作自定义工具栏
toolbar.xml工具栏.xml
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:titleTextColor="#FFFFFF">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left" />
<Button
android:id="@+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
Include the toolbar into your main_activity.xml将工具栏包含到您的 main_activity.xml
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <include android:id="@+id/toolbar" layout="@layout/toolbar" /> </RelativeLayout>
Don't forget to set the NoActionBar theme不要忘记设置 NoActionBar 主题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.