2014-12-05 113 views
8

我想使用Theme.AppCompat,但是當我做動作欄簡直就消失了。沒有任何錯誤或任何。Android - 操作欄不顯示使用Theme.AppCompat

事情是我在兩個更多的項目上使用這個確切的設置,他們工作得很好,不知道發生了什麼變化。

我也試着改變支持庫版本,父主題,清理項目,重建和無效緩存。不知道是否有任何幫助,但我做到了。

我使用過Android Studio 0.8.14

糾正我,如果我錯了,但是這就是我如何使用材料主題部件和調色板在舊的API,對不對?

預覽

enter image description here


styles.xml

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
    </style> 

</resources> 

的AndroidManifest.xml

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

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

的build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.1" 

    defaultConfig { 
     minSdkVersion 14 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      runProguard false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:21.0.2' 
} 

+1

appcompat的v21使用工具欄不是操作欄,您需要將工具欄放在視圖中。看到這個http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html – tyczj 2014-12-05 15:19:45

+1

@tyczj你絕對不需要在佈局中放置一個「工具欄」它完全是可選的。默認情況下'ActionBarActivity'會爲你解決,但你可以用你自己的方法來覆蓋。這些實現在v21中從「ActionBarImplVERSION」更改爲「ToolbarActionBar」/「WindowDecorActionBar」。 – TWiStErRob 2014-12-05 15:33:48

回答

17

我的答案應該是作爲一個註釋,但這是我能回答的唯一途徑。 是否在您的活動中延伸ActionBarActivity? 您是否在嘗試中嘗試了show()方法?

+1

我覺得真的很愚蠢,我完全忘記了擴展** ActionBarActivity **。好的,你寫了一個答覆我想,謝謝。 – Mody 2014-12-05 15:27:19

+0

很高興能幫到你! – 2014-12-05 15:29:20

+0

@Mody不要忘了接受答案,如果它的作品。 – TWiStErRob 2014-12-05 15:32:58