2016-07-19 66 views
2

我的代碼未顯示Kitkat上的工具欄。
這是我的Android版本的ScreenShot。我的工具欄在API級別21(Kitkat)上未顯示,但顯示爲API級別21

奇巧版本:

Kikat

棒棒糖版本:

Lollipop

什麼可能是背後的原因。

清單文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.global.market"> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/image_front" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 

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

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".detailactivity" 
      android:label="@string/app_name" /> 
     <activity 
      android:name="com.google.android.gms.ads.AdActivity" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

     <meta-data android:name="com.google.android.gms.version" android:value="6111000" /> 
    </application> 

</manifest> 

Styles.xml文件

<resources> 

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

    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="windowActionBarOverlay">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="windowActionBar">false</item> 
</style> 

<style name="AppTheme.NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 


    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 


    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     android:clickable="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

    <ExpandableListView 
     android:id="@+id/exp_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="160dp" 
     android:indicatorRight="?android:attr/expandableListPreferredItemIndicatorRight" 
     android:background="@android:color/white" 
     android:footerDividersEnabled="true" 
     android:groupIndicator="@null"> 
    </ExpandableListView> 

      <!--<ListView--> 
       <!--android:background="@android:color/white"--> 
       <!--android:id="@+id/menuList"--> 
       <!--android:layout_width="match_parent"--> 
       <!--android:layout_height="match_parent"--> 
       <!--android:layout_marginTop="10dp" />--> 
     </LinearLayout> 
    </android.support.design.widget.NavigationView> 

</android.support.v4.widget.DrawerLayout> 

MainActivity.java

 @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

       setContentView(R.layout.activity_main); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
       if (toolbar != null) { 
        toolbar = (Toolbar) findViewById(R.id.toolbar); 
        setSupportActionBar(toolbar); 
        getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
       } 
} 

的build.gradle文件

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    ext { 
     supportLibVersion = '23.4.0' // variable that can be referenced to keep support libs consistent 
    } 

    defaultConfig { 
     applicationId "com.global.market" 
     minSdkVersion 14 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 

    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile 'com.android.support:design:23.4.0' 
    compile 'com.loopj.android:android-async-http:1.4.9' 
    compile 'com.android.support:cardview-v7:23.0.+' 
    compile 'com.android.support:recyclerview-v7:23.0.+' 
    compile 'com.google.code.gson:gson:2.6.2' 
    compile 'com.squareup.retrofit2:retrofit:2.1.0' 
    compile 'com.squareup.retrofit2:converter-gson:2.1.0' 
    compile 'com.github.gabrielemariotti.cards:cardslib-core:2.1.0' 
    compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.1.0' 
    compile 'com.github.PhilJay:MPAndroidChart:v2.2.4' 
    compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar') 
    compile 'com.google.android.gms:play-services:6.1.11' 



} 

回答

6

AppBar默認有擡高其棒棒糖後的作品。因此,儘管佈局層次結構始終可見。但在較低版本(低於棒棒糖)下,工具欄可能會在某些其他佈局下繪製。

因此,重新排列布局項目以使工具欄可見。

+0

@Riyas Ahamed..Then,我應該把我的工具欄佈局? –

+0

發佈app_bar_main佈局代碼 –

+0

稍等片刻..我會在一分鐘內將編輯後的代碼發送給您。不要考慮上面的代碼。有一些缺失 –

0

更改style.xml

<resources> 

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

    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

MainActivity.java你initiliaze兩個時間ToolBar所以刪除第二行此

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

你不需要它。

+0

@鐵人三項 - 我已經做出了改變,但仍未奏效。 –

+0

@samarthkejriwal在'styles.xml'中有兩個文件,例如'styles.xml'和'styles.xml(v21)'。你可以發佈這兩個文件嗎? – Ironman

+0

styles.xml(V21) '> <樣式名稱= 「AppTheme.ActionBar」> <項名稱= 「windowActionBar」>假 <項目名稱= 「windowNoTitle」>真 <項目名稱= 「機器人:windowDrawsSystemBarBackgrounds」>真 <項目名稱= 「機器人:statusBarColor」> @安卓:彩色/透明 ' –

0

試試這個

更新style.xml

<resources> 

    <style name="AppTheme" parent="AppTheme.Base"> 

    </style> 

    <style name = "AppTheme.Base" parent="Theme.AppCompat.NoActionBar"> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 

</resource> 

並更新在AndroidManifest.xml活動主題文件

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

     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 
相關問題