侧滑界面/侧拉菜单
来源:互联网 发布:U递索引超出了数组界限 编辑:程序博客网 时间:2024/05/01 10:06
private DrawerLayout drawerLayout;
private FrameLayout frameLayout;
private ListView lv;
private ArrayList<String> lists;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initData();
setListener();
}
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
frameLayout = (FrameLayout) findViewById(R.id.frameLayout);
lv = (ListView) findViewById(R.id.lv);
}
lists = new ArrayList<>();
for (int i = 0; i < 5; i++) {
lists.add("DrawerLayout"+i);
}
ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1, lists);
lv.setAdapter(stringArrayAdapter);
}
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
MFragment mFragment = new MFragment();
Bundle bundle = new Bundle();
bundle.putString("name", lists.get(i));
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,mFragment).commit();
//关闭drawer
drawerLayout.closeDrawer(lv);
}
});
}
}
public class MFragment extends Fragment{
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstancState) {
TextView textView = new TextView(getActivity());
Bundle arguments = getArguments();
String name = arguments.getString("name");
textView.setText(name);
return textView;
}
}
//布局
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!--
和drawerLayout配合需要配这两个属性
android:layout_gravity="left"
android:choiceMode="singleChoice"
-->
<ListView
android:id="@+id/lv"
android:background="@color/colorPrimary"
android:layout_width="300dp"
android:layout_gravity="left"
android:choiceMode="singleChoice"
android:layout_height="match_parent"/>
- 侧滑界面/侧拉菜单
- 横滑菜单和侧拉菜单
- ios侧拉菜单
- 63.侧拉菜单
- SlidingMenu侧拉菜单
- 侧拉菜单
- 侧拉菜单
- SlidingPaneLayout:侧拉菜单
- slidingmenu侧拉菜单
- 侧拉新闻菜单
- 侧拉菜单
- 侧拉菜单
- 侧拉菜单显示
- 侧拉菜单
- 侧拉菜单
- 侧拉菜单
- 侧拉菜单(SlidingMenu)
- 侧拉菜单
- 9月6日云栖精选夜读:DMS前后端技术揭秘及最佳实践
- C语言基础 6 数组
- Ubuntu 14.04设置Proxy
- openshift/origin学习记录(1)——基于二进制文件的安装(单机版)
- 第27节:通过py2exe将自动化脚本打包成一个exe
- 侧滑界面/侧拉菜单
- Mysql VS2015调用
- Spring学习之路-装配Bean
- Vue.js使用Stylus
- JAVA设计模式之观察者模式
- VI在各类型活动展示中的要点
- Hadoop中的Hbase
- 选择子序列(51nod-1153)
- 自然语言处理(NLP)常用开源工具总结----不定期更新