gpt4 book ai didi

java - 您需要使用 Theme.AppCompat 主题

转载 作者:搜寻专家 更新时间:2023-11-01 08:31:26 25 4
gpt4 key购买 nike

是的,我知道,这个问题在这里一再发布。但是我找不到解决我的具体问题的方法。

每次我尝试制作 Snackbar 时,我的应用程序都会崩溃

You need to use a Theme.AppCompat theme (or descendant) with the design library.


好的。我知道:没有代码就无法调试,所以:

The call, and line that throws the error:

Snackbar.make(
new CoordinatorLayout(getApplicationContext()),
"Logged out.",
Snackbar.LENGTH_SHORT).show();


The class definition:

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {


Beginning of the manifest

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>

哦是的:AppTheme 和 AppTheme.NoActionbar 都是 Theme.AppCompat 的父类...


如果您需要更多代码,请告诉我。

最佳答案

为什么需要 CoordinatorLayoutgetApplicationContext()

您甚至可以使用 new CoordinatorLayout(MainActivity.this) 使其工作。 (这使用 Activity Context 而不是 Application Context

但是你真的应该保持简单。试试这个:

Snackbar.make(findViewById(android.R.id.content), "Logged out.", Snackbar.LENGTH_SHORT).show();

关于java - 您需要使用 Theme.AppCompat 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40333771/

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