Android中自定义工具栏的问题

问题描述 投票:1回答:1

我想完成以下任务

  • 删除默认工具栏
  • 构建自定义工具栏
  • 更改工具栏中的默认标题,标题文本颜色,标题文本对齐方式

我成功删除了默认工具栏,但在构建自定义工具栏时我无法做到

  • 更改标题文字颜色
  • 更改titleText对齐方式

我尝试了在堆栈溢出时提供给上述问题的现有解决方案,但在我的情况下似乎没有任何帮助

这是toolBar.xml文件

enter code here
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.toolbar
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:id="@+id/toolbarC"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"

android:theme="@style/Mystyle"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#ffffff">


</android.support.v7.widget.toolbar>

这是我的主要xml文件

enter code here`
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:layout="http://schemas.android.com/apk/res-auto"
android:background="#3dcc24">

<include
layout="@layout/clubs_tool_bar" />

</LinearLayout>

这是我的styles.xml文件

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="ColorTemp">@color/ColorTemp</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" 
parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="Mystyle" parent="ThemeOverlay.AppCompat.ActionBar">
    <item name = "android:textSize">30sp</item>



</style>
</resources>

enter image description here

这就是我的屏幕的样子

android android-layout android-toolbar
1个回答
2
投票

你需要解决相应的类,所以使用android.support.v7.widget.Toolbar

<android.support.v7.widget.Toolbar
    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:id="@+id/toolbarC"

    app:title="YourTitle"

    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"    
    android:theme="@style/Mystyle"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:titleTextColor="#ffffff"/>

代替

android.support.v7.widget.toolbar
© www.soinside.com 2019 - 2024. All rights reserved.