Android Material Design
来源:互联网 发布:mac美图秀秀 编辑:程序博客网 时间:2024/09/21 09:05
最近有的做手机项目,于是又接触 Android 了。
然后对 Material 比较感兴趣,总结些经验。
这篇文章主要是介绍 drawerlayout 。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?android:attr/actionBarSize" /> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> <FrameLayout android:background="#ff0000" android:layout_height="match_parent" android:layout_width="match_parent"> </FrameLayout> <!-- The navigation drawer --> <RelativeLayout android:background="#0000ff" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_gravity="start" android:id="@+id/navigation_drawer"> </RelativeLayout> </android.support.v4.widget.DrawerLayout></LinearLayout>
Drawerlayout 下一般放两到三个布局,也可以直接放 fragment,动态替换 fragment 也可以。
三个布局分别代表,主页面,左边栏,右边栏,区分的关键就是 layout_gravity="start|left"。
照这种布局,侧边栏是不会把 toolbar 遮住的。
https://github.com/blackcj/android-toolbar-with-drawer 这里补充了遮护 toolbar 的例子。
如果不想边栏遮住状态栏,可以添加 android:fitsSystemWindows="true"。
如果想要这种很酷的效果:
http://chrisrenke.com/drawerarrowdrawable/
public class ToolbarActivity extends ActionBarActivity { private ActionBarDrawerToggle toggle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close);// toggle.setDrawerIndicatorEnabled(true); drawerLayout.setDrawerListener(toggle); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); toggle.syncState(); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.toolbar, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { if (toggle.onOptionsItemSelected(item)) return true; int id = item.getItemId(); return id == R.id.action_settings || super.onOptionsItemSelected(item); }
这里没有用 fragment,所以 activity recreate 时也不用去管。
顺便一提,22 里 ActionBarActivity 也过时了。
0 0
- Android Material Design尝鲜
- Android Material Design
- Android Material Design Dialog
- Android:Material Design详解
- Android Material Design:PopupMenu
- Android Material Design:ListPopupWindow
- Android Material Design-UI
- Android Material Design动画
- Android Material Design:PopupMenu
- android Material design
- Android Material Design详解
- Android Material Design theme
- android Material Design详解
- Android Material Design简介
- Android Material Design theme
- android material design 主题
- Android Material Design
- Android material design
- 将自己的本地项目上传到svn
- 信息增益与决策树
- 用js操作table、tr、td 「字体样式及TD背景图片」
- 关于Debug和Release之本质区别
- Android的内存泄露问题
- Android Material Design
- 安装vnc-server
- Android之读取 AndroidManifest.xml 中的数据:版本号、应用名称、自定义K-V数据(meta-data)
- 循环顺序队列
- koala 多数据源动态切换
- ASP.NET Web Forms - Master Pages
- sql中的常用函数
- nodejs学习:express本地、响应全局变量
- Servlet的生命周期与工作原理