2015-05-15 118 views
1

導航抽屜開口不打開上點擊導航圖標(左上屏幕上即3水平線)。在棒棒糖它正在工作,但問題是與奇巧和果凍豆它不工作?導航抽屜上沒有點擊菜單圖標

Styles.xml

<resources> 

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="windowActionBar">false</item> 
    <item name="android:windowActionBarOverlay">true</item> 
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> 
    <item name="spinBars">true</item> 
    <item name="color">@android:color/white</item> 
</style> 

AndroidManifes.xml

<application 
    android:name="com.volley_network_thread.AppController" 
    android:icon="@mipmap/ic_launcher" 
    android:allowBackup="true" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme"> 

    ...... 
    ...... 
    ...... 
    ...... 
</application> 

toolbar.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/app_theme_red_color" 
android:elevation="4dp" 
android:minHeight="?attr/actionBarSize" 
android:title="@string/app_name"> 

activity_home.xml

<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" 
tools:context=".MainActivity"> 


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

    <include layout="@layout/toolbar"></include> 
</FrameLayout> 

<LinearLayout 
    android:layout_width="300dp" 
    android:layout_height="fill_parent" 
    android:layout_gravity="start" 
    android:background="#FFF" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="75dp" 
     android:layout_gravity="center" 
     android:background="@drawable/drawer_profile_bg"> 

     <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/imageView_round" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginTop="15dp" 
      android:src="@drawable/disp" 
      app:border_color="@color/gray_border" 
      app:border_width="2dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:text="ex : John Mathew" 
      android:textColor="@color/white" 
      android:textStyle="bold" /> 
    </RelativeLayout> 

    <ListView 
     android:id="@+id/drawer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#FFF" 
     android:choiceMode="singleChoice" /> 

    <ExpandableListView 
     android:id="@+id/lvExp" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" /> 

</LinearLayout> 

Home.java

public class Home extends ActionBarActivity { 
Toolbar toolbar; 
final String[] data = {"Locate People", "Account Setting"}; 
DrawerLayout drawer; 
ActionBarDrawerToggle mDrawerToggle; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_home); 
    initialize(); 
    setToolbar(0); 

} 

private void initialize() { 
    toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setHomeButtonEnabled(true); 

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

     public void onDrawerClosed(View view) { 
      invalidateOptionsMenu(); 
     } 


     public void onDrawerOpened(View drawerView) { 
      invalidateOptionsMenu(); 
     } 
    }; // Drawer Toggle Object Made 
    drawer.setStatusBarBackgroundColor(getResources().getColor(R.color.app_theme_red_color)); 
    drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle 
    mDrawerToggle.syncState();    // Finally we set the drawer toggle sync State 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Pass the event to ActionBarDrawerToggle, if it returns 
    // true, then it has handled the app icon touch event 
    if (mDrawerToggle.onOptionsItemSelected(item)) { 
     return true; 
    } 
    // Handle your other action bar items... 

    return super.onOptionsItemSelected(item); 
} 

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
    mDrawerToggle.onConfigurationChanged(newConfig); 
} 
@Override 
protected void onPostCreate(Bundle savedInstanceState) { 
    super.onPostCreate(savedInstanceState); 
    mDrawerToggle.syncState(); 
} 
public void setToolbar(int position) { 
    if (position == 0) { 
     toolbar.setTitle("Establishemnt"); 
     toolbar.setTitleTextColor(getResources().getColor(R.color.white)); 
    } else if (position == 1) { 
     toolbar.setTitle("Settings"); 
     toolbar.setTitleTextColor(getResources().getColor(R.color.white)); 
    } 
} 

}

+1

發表您的'activity_home' – SilentKnight

+0

@SilentKnight佈局請檢查我已經加入佈局文件也 – Shanmugapriyan

+0

儘量把你的非抽屜查看到的FrameLayout – Demonick

回答

1

你的代碼看起來一團糟,看看我的,它工作得很好。

public class HomeActivity extends ActionBarActivity implements 
     DrawerCloseListener { 
    private Toolbar toolbar; 
    private DrawerLayout drawer; 
    private ActionBarDrawerToggle drawerToggle; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_home); 
     toolbar = (Toolbar) findViewById(R.id.home_toolbar); 
     setSupportActionBar(toolbar); 
     drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     drawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, 
       R.string.app_name, R.string.app_name); 
     drawerToggle.setHomeAsUpIndicator(R.drawable.icon_nav); 
     drawer.setDrawerListener(drawerToggle); 
    } 

    @Override 
    protected void onResume() { 
     // TODO Auto-generated method stub 
     super.onResume(); 
     toolbar.setTitle(""); 
     toolbar.setNavigationIcon(R.drawable.icon_nav); 
    } 

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

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     if (drawerToggle.onOptionsItemSelected(item)) { 
      return true; 
     } 
     // 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. 
     return super.onOptionsItemSelected(item); 
    } 

    @Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     // TODO Auto-generated method stub 
     super.onConfigurationChanged(newConfig); 
     drawerToggle.onConfigurationChanged(newConfig); 
    } 

    @Override 
    protected void onPostCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onPostCreate(savedInstanceState); 
     drawerToggle.syncState(); 
    } 

    @Override 
    public void onBackPressed() { 
     // TODO Auto-generated method stub 
     if (drawer.isDrawerOpen(Gravity.LEFT | Gravity.START)) { 
      drawer.closeDrawers(); 
      return; 
     } 
     super.onBackPressed(); 
    } 

    @Override 
    public void onDrawerClose() { 
     // TODO Auto-generated method stub 
     if (drawer.isDrawerOpen(Gravity.LEFT | Gravity.START)) { 
      drawer.closeDrawers(); 
     } 
    } 
} 
+0

不行不行。還是同樣的問題 – Shanmugapriyan

2

我今天面臨這個問題。

我認爲這可能是你DrawerLayout是在根視圖,並設置寬度和高度= "match_parent"

Lolipop,工具欄是彈出式的,所以它是可點擊的。但在KitKat或更低版本中,它將單擊DrawerLayout,而不是工具欄(工具欄位於DrawerLayout後面)。

我的解決辦法是設置在MarginTop = "?attr/actionBarSize" DrawerLayout。

希望這將幫助您認爲這是已經有很長一段時間:)

+0

這對我沒有用。 – Bot