提问人:Samwise Ganges 提问时间:7/22/2023 更新时间:7/22/2023 访问量:28
为什么这个主题没有应用于这个 Android 工具栏小部件?
Why is this theme not being applied to this Android toolbar widget?
问:
我正在使用 Android Studio 创建一个 Java Android 应用程序。我通过 setSupportActionBar 创建了一个自定义工具栏来代替默认操作栏。除了我的自定义主题根本没有应用于工具栏之外,一切正常。它被正确地应用于其他一切。
下面是工具栏 XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/baseLight"
android:elevation="4dp"
android:theme="@style/Base.Theme.BeatCube"
>
</androidx.appcompat.widget.Toolbar>
下面是导入工具栏的主要活动 XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="0dp"
tools:context="com.therealsamchaney.beatcube.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
/>
<LinearLayout
android:id="@+id/topLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:layout_editor_absoluteX="1dp"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:layout_constraintBottom_toTopOf="@id/grid_container"
tools:layout_editor_absoluteY="65dp">
<ToggleButton
android:id="@+id/recordPlayToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="Record/Play"
android:textOff="In Play Mode"
android:textOn="In Record Mode" />
</LinearLayout>
<FrameLayout
android:id="@+id/grid_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/bottomLinear"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topLinear">
<!-- app:layout_constraintDimensionRatio="1:1"-->
</FrameLayout>
<LinearLayout
android:id="@+id/bottomLinear"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@id/grid_container"
app:layout_constraintBottom_toBottomOf="parent"
>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
以下是带有自定义主题的主题 .xml 文件:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.BeatCube" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
<item name="android:textColor">@color/text</item>
<item name="android:windowBackground">@color/baseDark</item>
<item name="android:fontFamily">serif</item>
</style>
<style name="Theme.BeatCube" parent="Base.Theme.BeatCube" />
<style name="BeatCubeDialog" parent="Theme.AppCompat.Dialog">
<item name="android:textColor">@color/text</item>
<item name="android:windowBackground">@color/baseDark</item>
<item name="android:fontFamily">serif</item>
</style>
这里也是清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<application
android:name="com.BeatCube"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.BeatCube"
tools:targetApi="31">
<activity
android:name="com.therealsamchaney.beatcube.RecordActivity"
android:exported="false"
android:theme="@style/BeatCubeDialog"
/>
<activity
android:name="com.therealsamchaney.beatcube.MainActivity"
android:exported="true"
android:theme="@style/Base.Theme.BeatCube"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
答: 暂无答案
评论