android抽屉导航

今天学习了一种制作简单android抽屉导航的方法。

建立项目时选取:

这样android IDE 就会给你一个抽屉导航的框架。

我们只需要修改MainActivity中的PlaceholderFragment类中的:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);  
   textView.setText("第"+Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER))+"部分");  
return rootView;
}

就可以根据etArguments().getInt的到相应得到 position对应显示相应的主界面。

而左边导航抽屉界面就更容易了,我们只需要改一下NavigationDrawerFragment类中的:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mDrawerListView = (ListView) inflater.inflate(
R.layout.fragment_navigation_drawer, container, false);
mDrawerListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
selectItem(position);
}
});
mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar()
.getThemedContext(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1, new String[] {
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
getString(R.string.title_section4),
getString(R.string.title_section5), }));
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
}

这一部分就行了。

还可以通过修改fragment_main.xml先建立一个大致的总体布局

这样就建立了一个自己的简单的导航抽屉。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值