1.app主题使用理解
- 基本主题使用
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item> <!-- 标题栏的背景色 -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <!-- 顶部显示时间,网络时的背景色 -->
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
- toolbar使用
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="?attr/colorPrimary"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_height="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
2.滑动菜单
DrawerLayout :这是一个布局,允许直接放入两个子控件;第一个子控件是主屏幕中显示的内容;第二个子控件是滑动菜单中显示的内容。第二个子控件中的layout_gravity属性必须指定,这是判断屏幕左滑还是右滑出现抽屉菜单的。
NavigationView:放置在DrawerLayout下,作为第二个子控件; NavigationView中有两个子布局:nav_menu,headerlayout;
<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">
<TextView
android:text="fff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/headerlayout"
app:menu="@menu/nav_menu" />
</android.support.v4.widget.DrawerLayout>
//点击事件处理
mDrawerLayout= (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView= (NavigationView) mDrawerLayout.findViewById(R.id.nav_view);
navigationView.setCheckedItem(R.id.nav_call);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.nav_bike:
Toast.makeText(NavigationActivity.this,"bike",Toast.LENGTH_SHORT).show();
break;
case R.id.nav_call:
Toast.makeText(NavigationActivity.this,"call",Toast.LENGTH_SHORT).show();
break;
case R.id.nav_eat:
Toast.makeText(NavigationActivity.this,"eat",Toast.LENGTH_SHORT).show();
break;
}
mDrawerLayout.closeDrawers();
return true;
}
});
- FloatingActionButton 悬浮按钮,普通按钮使用
<android.support.design.widget.FloatingActionButton
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
/>
- Snackbar 提示布局,底部出现,类似Toast
- 卡片式布局
3.优雅的显示
- 解决控件间的遮挡问题
- recycleview向下滑动的时候,toolbar隐藏,向上出现解决方式
<?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">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways|snap" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="@drawable/ic_done" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_menu" />
</android.support.v4.widget.DrawerLayout>
下拉刷新控件
可折叠式标题栏
充分利用系统状态栏空间