我试图找到我的抽屉布局,但findViewById返回null,我不知道为什么......这是我的代码。
// NavigationBaseActivity
@Override
public void setContentView(int layoutResID) {
LayoutInflater.from(this).inflate(layoutResID, (ViewGroup) findViewById(R.id.content), true);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawerLayout != null) {
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_open, R.string.navigation_close);
drawerLayout.setDrawerListener(drawerToggle);
}
setupToolbar();
}
public class OverviewActivity extends NavigationBaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_overview);
}
}
我的drawerLayout总是为null ...这是我的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"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
</LinearLayout>
<include layout="@layout/navigation"/>
</android.support.v4.widget.DrawerLayout>
任何人都可以帮助我..我可以找到其他人的观点,但抽屉布局很顽固......谢谢