2016-10-30 8 views
2

はい、私は知っている、この問題は何度も繰り返し投稿されました。しかし私は私の特定の問題に対する解決策を見つけることができません。Theme.AppCompatテーマを使用する必要があります

私はスナックバーをしようとするたびに、私のアプリは、[OK]を

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の両方の親です...


あなたはもうコードが必要な場合は、ちょうど私に言います。

+0

は 'のRES /値/ styles.xml'と'のres /値-V21 /スタイルを追加します。 .xml'(もしあなたがそれを持っていれば)、 –

答えて

2

なぜCoordinatorLayoutgetApplicationContext()が必要ですか?

new CoordinatorLayout(MainActivity.this)でも動作させることができます。 。(これは

ActivityContextの代わりApplicationContextを使用していますしかし、あなたは本当に簡単にそれを維持する必要があり、この試してみてください:。

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

phewをください...それは簡単でした...とてもありがとうございます:) – Malik

関連する問題