2016-07-15 12 views
1

アンドロイドスタジオアクティビティギャラリーからアクティビティを作成しました。私はアプリを実行すると、次のロリポップバージョンの下にアクションバー/ツールバーが表示されない

は、アクションバーは、ロリポップ以下でショーlayout.xmlファイル

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.atgarage.Home.HomeActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <!--<include layout="@layout/content_home" />--> 

    <FrameLayout 
     android:id="@+id/mainfragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</android.support.design.widget.CoordinatorLayout> 

のコードをないがされているが、上記ロリポップで実行すると、それは完全に表示されます。

次のアプリケーションスタイルがあります。

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="android:windowNoTitle">true</item> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="windowNoTitle">true</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="android:windowFullscreen">true</item> 
    </style> 

いずれも解決策があります。

ありがとうございます。

答えて

1

フラグメントのコンテナレイアウトに上端余白を使用して固定されています。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.atgarage.Home.HomeActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <!--<include layout="@layout/content_home" />--> 

    <FrameLayout 
     android:id="@+id/mainfragment" 
     android:layout_width="match_parent" 
     android:layout_marginTop="?attr/actionBarSize" 
     android:layout_height="match_parent" /> 

</android.support.design.widget.CoordinatorLayout> 
0

あなたは追加する必要があります -

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

あなたの活動のonCreate()方法で。

+0

はい。私は自分の活動で行っていますonCreate() – Naitik

+0

フレームレイアウトは下のAPIの全画面をカバーしていると思います –

1

変更この

<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" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="android:windowNoTitle">true</item> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="windowNoTitle">true</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="android:windowFullscreen">true</item> 
    </style> 

Manifest.xmlファイル

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

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

私はこれを変更しましたが、同じ問題にまだ直面しています – Naitik

+0

@Naitikはあなたにこれを設定しましたandroid:theme = "@ style/AppTheme.NoActionBar "'このスタイルを 'manifest.xml'ファイルに入れてください。そうでなければ' manifest.xml'ファイルを投稿してください。 – Ironman

+0

@Naitikはそれを得ましたか? – Ironman

0

あなたの活動のsh OULLDはAppCompatActivityではなく、Activityなどを拡張します。そして、あなたは

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

を使用することができますネブラスカ編集:すべての

まず、あなたはそのcontent_home.xmlを使用し、そこにすべてを配置する必要があります。それは一般的な慣習であり、Googleはそれを裏付けるいくつかの理由を意味するデフォルトにした。その結果、FrameLayoutcontent_home.xml

に移動する必要があります。あなたのケースでは、私は新しいプロジェクトを作成して同じことを試し、API 19デバイスでテストしました。これは、次の設定で働いていた:

のAndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.marat.testingapp"> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     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> 
    </application> 

</manifest> 

activtiy_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.example.marat.testingapp.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <FrameLayout 
     android:id="@+id/frameLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</android.support.design.widget.CoordinatorLayout> 

の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> 
    </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" /> 

</resources> 

MainActivity。java

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
    } 
} 

コードとこのコードを比較してください。

+0

私は上記のコードも書いています。まだ動作していません – Naitik

+0

@Naitik私は私の答えを更新しました。それを見てください – Marat

+0

@ Naitikはあなたに役立つ私の答えでしたか? – Marat

関連する問題