android - 如何使 Android 标签居中
问题描述
一直试图将我的 android 标签居中。我应该为此使用操作栏吗?
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:exported="true"
android:theme="@style/Theme.TurboMileage">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
这是我的strings.xml
<resources>
<string name="app_name">Turbo Mileage</string>
解决方案
您必须将主题与 NoActionBar 一起使用并创建工具栏:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/colorPrimary"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toEndOf="@+id/ivSetting"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="@dimen/font_normal" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/ivBack"
android:layout_width="?actionBarSize"
android:layout_height="match_parent"
android:background="?android:selectableItemBackground"
android:padding="@dimen/spacing_normal"
app:srcCompat="@drawable/ic_back" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
推荐阅读
- python - TemplateSyntaxError 'apptags' 不是注册的标签库
- c++ - 如何通过 CMake 构建具有交叉方法名称的多个共享库
- reactjs - 如何将downloadjs导入react js文件?
- css - 如何从标题中删除css中的空格
- html - 防止同名网格单元堆叠
- visual-studio-code - 检查调试控制台是否处于活动状态的“何时”条件是什么?
- flutter - 为什么降级 Flutter App 会导致数据丢失?
- typescript - 使用带有 typescript 的 httpService 执行请求时出错
- apache-zeppelin - Apache Zeppelin:interpreter.json 不断重置
- android - Android导航组件:有什么方法可以以编程方式更改BottomNavigation的选定选项卡