日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android普通对话框标题居中,android开发Toolbar标题居中显示的解决方法

發布時間:2023/12/19 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android普通对话框标题居中,android开发Toolbar标题居中显示的解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

網上的一大堆,都是有問題不完整的,互相copy。。。記錄一下自己的解決方法。

android:id="@+id/tool_bar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:titleMargin="0dp"

app:contentInsetEnd="0dp"  //重要

app:contentInsetStart="0dp"  //重要

app:navigationIcon="@drawable/ic_launcher">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"  //重要

android:textSize="20sp"

android:singleLine="true"

android:textColor="@android:color/black"

android:text="居中顯示居中顯示" />

另外附上menu的例子代碼:res/menu/menu_tool_bar.xml

xmlns:app="http://schemas.android.com/apk/res-auto">

android:id="@+id/action_search"

android:icon="@android:drawable/ic_menu_search"

android:title="menu_search"

app:showAsAction="ifRoom" />

android:id="@+id/action_item_one"

android:icon="@android:drawable/ic_menu_add"

android:title="menu_more"

app:showAsAction="never" />

java代碼如下:

val toolbar = findViewById(R.id.tool_bar)

toolbar.inflateMenu(R.menu.menu_tool_bar)

toolbar.setOnMenuItemClickListener設置menuItem的點擊事件

另外:我的Activity是繼承FragmentActivity的,不用調用setSupportActionBar(toolbar),但是需要配置AppTheme。如下:

@color/colorPrimary

@color/colorPrimaryDark

@color/colorAccent

總結

以上是生活随笔為你收集整理的Android普通对话框标题居中,android开发Toolbar标题居中显示的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。