2016-10-26 14 views
0

私はアンドロイドアプリケーションにナビゲーションを追加します。ナビゲーションドロワーは他のコンポーネントをブロックします

私は成功したナビゲーションの引き出しを追加this tutorial

を追いました。 問題は、コンポーネントを追加すると、他のボタンとコンポーネントが非アクティブになることです。アクションバーの3つの点のように、項目をリストしません。 Drawerレイアウトの表示を消してしまうと、アクションバーの3つのドットが動きます。これは私のcontent_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.example.hale.myapplication.MainActivity" 
tools:showIn="@layout/activity_main"> 
<include layout="@layout/app_bar"/> 

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:visibility="gone"> 


<ListView 
    android:id="@+id/navList" 
    android:layout_width="200dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="left|start" 
    android:background="#ffeeeeee"/> 

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

</RelativeLayout> 

これは、ここでapp_bar.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.example.hale.myapplication.MainActivity" 
tools:showIn="@layout/activity_main"> 
<include layout="@layout/app_bar"/> 

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:visibility="gone"> 


<ListView 
    android:id="@+id/navList" 
    android:layout_width="200dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="left|start" 
    android:background="#ffeeeeee"/> 

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

</RelativeLayout> 

あるスクリーンショットである

public class MainActivity extends AppCompatActivity { 

public android.support.v7.widget.Toolbar toolbar; 
private ListView mDrawerList; 
private ArrayAdapter<String> mAdapter; 
private ActionBarDrawerToggle mDrawerToggle; 
private DrawerLayout mDrawerLayout; 
private String mActivityTitle; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    mDrawerList = (ListView) findViewById(R.id.navList); 
    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      Toast.makeText(MainActivity.this, "Time for an upgrade!", Toast.LENGTH_SHORT).show(); 
     } 
    }); 

    mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); 
    mActivityTitle = getTitle().toString(); 
    addDrawerItems(); 

    setupDrawer(); 
    toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.app_bar_id); 
    setSupportActionBar(toolbar); 

    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setHomeButtonEnabled(true); 

} 

private void setupDrawer() { 

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 
      R.string.drawer_open, R.string.drawer_close) { 

     /** Called when a drawer has settled in a completely open state. */ 
     public void onDrawerOpened(View drawerView) { 
      super.onDrawerOpened(drawerView); 
      getSupportActionBar().setTitle("Navigation!"); 
      invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 
     } 

     /** Called when a drawer has settled in a completely closed state. */ 
     public void onDrawerClosed(View view) { 
      super.onDrawerClosed(view); 
      getSupportActionBar().setTitle(mActivityTitle); 
      invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 
     } 
    }; 

    mDrawerToggle.setDrawerIndicatorEnabled(true); 
    mDrawerLayout.setDrawerListener(mDrawerToggle); 
} 


private void addDrawerItems() { 
    String[] osArray = { "Android", "iOS", "Windows", "OS X", "Linux" }; 
    mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray); 
    mDrawerList.setAdapter(mAdapter); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (mDrawerToggle.onOptionsItemSelected(item)) { 
     return true; 
    } 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

@Override 
protected void onPostCreate(Bundle savedInstanceState) { 
    super.onPostCreate(savedInstanceState); 
    mDrawerToggle.syncState(); 
} 

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
    mDrawerToggle.onConfigurationChanged(newConfig); 
} 
} 

は、ここに私のコードです。 3つのドットはタイトルの近くにあります screenshot

ありがとうございます。この

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


<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="colorControlHighlight">@color/colorAccent</item> 
    <item name="toolbarStyle">@style/Toolbar</item> 
    <item name="android:windowBackground">@android:color/white</item> 
</style> 

<style name="Toolbar" parent="Base.Widget.AppCompat.Toolbar"> 
    <item name="android:background">?attr/colorPrimary</item> 
    <item name="popupTheme">@style/Theme.AppCompat.Light</item> 
</style> 

のようなものに

+0

今追加あなたのレイアウトのコードは、私たちに私はforgat – xFighter

+0

感謝を示しました。 – Hilal

+0

もう、もう1つ質問してもらえません。スクリーンショットをアップロードできますか? – xFighter

答えて

0

最初の変更あなたのテーマは、これは、私はあなたがdrawerLayoutを参照してください、私のメインのコンテンツのレイアウトを使用する方法であり、この内、私はにコンテンツを追加でframeLayoutを持っている、のLinearLayoutを持っていますショー。 GoogleではListViewの代わりにNavigationViewerを使用してください。

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


    <!-- this is your ActionBar layout --> 
    <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:fitsSystemWindows="true" 
     android:layout_height="?attr/actionBarSize" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 


    <!-- Your content goes inside this layout --> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" /> 

</LinearLayout> 



<!-- you should use such NavigatinView instead of ListView --> 
<android.support.design.widget.NavigationView 
    android:id="@+id/navigation.view" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:headerLayout="@layout/navigation_profile" 
    app:itemBackground="@xml/activated_navigation_menu_item" 
    app:menu="@menu/navigation_menu"/> 

+0

さて、やったよ。しかし、今私はonclickでどのように表示を隠して表示できますか?それは開いている – Hilal

+0

あなたは話しているのですか? – xFighter

+0

ナビゲーションビュー – Hilal

関連する問題