gpt4 book ai didi

Android 主题错误的

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:21:56 25 4
gpt4 key购买 nike

我想为我的应用制作新主题(一个主题在 < v21 之前,一个主题在 >=v21 之后)。

这是来自 Activity 的代码:

  protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.DriverNotesAppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tool_bar_test);

toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}

XML 布局工具栏:

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/DriverNotesAppTheme"
app:theme="@style/DriverNotesAppTheme">

这是v21之前的主题:

<style name="DriverNotesAppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- customize the color palette -->
<item name="colorPrimary">@color/material_bg</item>
<item name="colorPrimaryDark">@color/status_bar</item>
<item name="colorAccent">@color/edittext_primary</item>
<item name="android:windowBackground">@color/light_blue</item>
</style>

这是 v21 的主题及更高:

<style name="DriverNotesAppTheme" parent="android:Theme.Material">
<!-- customize the color palette -->
<item name="colorPrimary">@color/material_bg</item>
<item name="colorPrimaryDark">@color/status_bar</item>
<item name="colorAccent">@color/edittext_primary</item>
<item name="android:windowBackground">@color/light_blue</item>
</style>

这是截图: enter image description here v21及更高;

enter image description here

之前v21

以及来自资源的颜色: enter image description here

最佳答案

代码更正

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tool_bar_test);

toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

在您的工具栏中设置主题

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/<Your Theme Name>"
app:theme="@style/<Your Theme Name>"/>

关于Android 主题错误的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33892464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com