gpt4 book ai didi

android - 错误 : ToolBar theme and Dark theme

转载 作者:行者123 更新时间:2023-11-29 19:29:24 26 4
gpt4 key购买 nike

我正在为我的工具栏使用当前的样式和主题,并使用一个支持库。我正在扩展 AppCompatActivity 而不是正常 Activity 。

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">      <item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
</style>

我收到错误,下面是堆栈跟踪,

Process: com.random.simplenotes, PID: 2176
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to com.android.internal.widget.ActionBarOverlayLayout$LayoutParams
at com.android.internal.widget.ActionBarOverlayLayout.applyInsets(ActionBarOverlayLayout.java:172)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:317)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Application terminated.

主要 Activity

当我尝试应用深色主题时出现问题。parent="Theme.AppCompat.DayNight.NoActionBar" 对于此属性,我如何知道哪些主题可以工作,哪些不会?以及应该如何应用不会出现任何错误的深色主题?

让我知道还需要什么代码,我会相应地编辑问题。

编辑 1根据评论中的要求,我添加了 Activity onCreate() 方法

初始化

 DataBaseHelper dbhelper;
ListView notesView;
CustomCursor dataCursor;
int ROW_NUMBER;
Cursor passCursor;
Toolbar bar;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbhelper = new DataBaseHelper(this);

passCursor = dbhelper.fetchAllNotes();
dataCursor = new CustomCursor(this,passCursor);

notesView = (ListView)findViewById(R.id.listView);
notesView.setAdapter(dataCursor);
notesView.setOnItemClickListener(this);

bar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(bar);

}

最佳答案

删除 <item name="android:windowActionBar">true</item>如果您使用的是 Toolbar,则来自您的主题文件对于一个 supportActionBar

关于android - 错误 : ToolBar theme and Dark theme,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40425051/

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