如何将工具栏中的图标与中间对齐?我已经删除了标签getSupportActionBar().setDisplayShowTitleEnabled(false);
为我的工具栏创建一个xml文件是最好的主意吗?对齐工具栏中的图标
0
A
回答
1
是在工具栏中创建一些布局,并在布局中可以有其他控件(视图)。
工具栏与其他布局类似,可以嵌套它们。 。
mToolbar.getViewTreeObserver()addOnGlobalLayoutListener(新ViewTreeObserver.OnGlobalLayoutListener(){ @覆盖 公共无效onGlobalLayout(){ ImageView的ImageView的=(ImageView的:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="@string/news"/>
</RelativeLayout>
</Toolbar>
1
编程,你可以如下做到这一点)mToolbar.findViewById(R.id.logo); 如果(mToolbar == NULL){ 回报; } INT toolbarWidth = mToolbar.getWidth(); INT imageWidth = imageView.getWidth(); imageView.setX((toolbarWidth-imageWidth)/ 2); } }); 定制您的layout_toolbar.xml:
<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"
style="@style/Toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="@drawable/toolbar_background"
android:focusable="false"
app:titleTextAppearance="@style/AppTheme.Toolbar.Title">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/toolbar_logo"/>
</android.support.v7.widget.Toolbar>
相关问题
- 1. 将Eclipse工具栏图标左对齐
- 2. 将图标与工具栏图标对齐 - Android Material Design
- 3. 工具栏中的标题图像对齐方式android
- 4. Android的导航工具栏图标和标识不能对齐
- 5. 如何对齐工具栏上的UIBarButtonItem?
- 6. 如何向右对齐Android中工具栏上的图像
- 7. 右上对齐的MFC工具栏对齐
- 8. Ios ::工具栏对齐问题
- 9. CKEditor文本对齐工具栏按钮
- 10. WebView和工具栏不会对齐
- 11. 自定义工具栏布局对齐
- 12. 黑莓UI工具栏:字段对齐
- 13. 通过代码左对齐工具栏
- 14. 工具栏标题的项目对齐问题?
- 15. 如何与工具栏的标题对齐?
- 16. 工具栏中的图标不出现
- 17. Android的工具栏菜单图标和文本没有正确对齐
- 18. 将SearchView提示与工具栏标题展开后对齐
- 19. 操作栏(工具栏)图标
- 20. 工具栏图标不居中
- 21. 在gtk工具栏中排列图标
- 22. 从AppCompat继承工具栏更改工具栏图标边距
- 23. Eclipse RCP:工具栏中的右对齐搜索字段
- 24. MFC应用程序中的工具栏对齐
- 25. 如何对齐工具栏中的textview和tablayout
- 26. 用图标替换工具栏标题
- 27. 如何让自定义工具栏与操作栏对齐?
- 28. 新创建的工具栏图标不显示在工具栏中
- 29. Firefox扩展的工具栏图标
- 30. 工具栏 - 图标的深度颜色