赞
踩
<color name="main_color">#ffffff</color>
Snackbar.make(coordinator,"Snackbar",Snackbar.LENGTH_SHORT)
.setAction("撤销", new View.OnClickListener() {
@Override
public void onClick(View v) {
text.setText("撤销");
}
}).show();
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) text.getLayoutParams();
SwipeDismissBehavior behavior=new SwipeDismissBehavior();
behavior.setListener(this);
layoutParams.setBehavior(behavior);
public void onDismiss(View view) {
text.setVisibility(View.GONE);
Snackbar.make(coordinator,"你删除了一个textview",Snackbar.LENGTH_LONG)
.setAction("撤销", new View.OnClickListener() {
@Override
public void onClick(View v) {
text.setVisibility(View.VISIBLE);
ViewCompat.setAlpha(text,1);
ViewCompat.setTranslationX(text,0);
}
}).show();
}
@Override
public void onDragStateChanged(int state) {
}
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="@+id/main_toolbar">
setSupportActionBar(toolbar);
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/drawer_layout2">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00f"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00"/>
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
//好像联想不出来
android:layout_gravity="start"
//头布局,另写xml
app:headerLayout="@layout/content_header"
//布局菜单类型,另写xml
app:menu="@menu/menu_navigation"
//图片颜色
app:itemIconTint="@color/color_menu_item"
//文字颜色
app:itemTextColor="@color/color_menu_item"
//字体大小
app:itemTextAppearance="?android:textAppearanceLarge"
android:background="#fff">
</android.support.design.widget.NavigationView>
drawer = (DrawerLayout) findViewById(R.id.drawer_layout2);
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, 0, 0);
drawer.setDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
drawer_layout = (DrawerLayout) findViewById(R.id.drawer_layout);
toggle=new ActionBarDrawerToggle(this,drawer_layout,0,0);
drawer_layout.setDrawerListener(toggle);
toggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return toggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
}
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_add"
//布局以什么为基准
app:layout_anchor="@id/collapsing_toolbar3"
//根据基准设置布局方式
app:layout_anchorGravity="bottom|right|end"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:id="@+id/bar_button"/>
navigationView.setNavigationItemSelectedListener(this);
@Override
public boolean onNavigationItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item_1:
break;
case R.id.item_2:
break;
case R.id.item_3:
break;
case R.id.item_4:
break;
case R.id.item_5:
//退出整个应用程序
ActivityCompat.finishAffinity(this);
break;
}
//关闭NavigationView
drawer.closeDrawer(GravityCompat.START);
return false;
}
<android.support.design.widget.AppBarLayout
android:layout_height="192dp"
android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar3"
android:layout_width="match_parent"
android:layout_height="match_parent"
//想有折叠效果必须有这个属性
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar3"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
//折叠模式
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="LinearLayoutManager"
//和AppBarLayout.ScrollingViewBehavior相匹配,用来通知AppBarLayout 这个特殊的view何时发生了滚动事件,这个behavior需要设置在触发事件(滚动)的view上
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/recycle">
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
//可写可不写,看自己喜欢哪种样式
app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="@+id/appbar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
//折叠后的背景颜色
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="320dp"
android:src="@mipmap/ic_launcher"
app:layout_collapseMode="parallax"
/>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin"
android:id="@+id/toolbar"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar3);
collapsingToolbar.setTitle("cheeseName");
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
//设置滚动还是占满一行
app:tabMode="fixed"
app:tabTextAppearance="@style/tabTextAppearance"
app:tabBackground="@color/colorPrimaryDark"
app:tabTextColor="#fff"
app:tabIndicatorHeight="0dp"
app:tabSelectedTextColor="@color/colorAccent"
app:tabIndicatorColor="@color/colorAccent"
android:id="@+id/tab"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text_input">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入用户名"
android:id="@+id/edit_text"/>
</android.support.design.widget.TextInputLayout>
textInput = (TextInputLayout) findViewById(R.id.text_input);
edit.addTextChangedListener(this);
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() < 6) {
textInput.setError("用户名要大于6位");
textInput.setErrorEnabled(true);
} else {
textInput.setErrorEnabled(false);
}
}
public class MyBehavior extends FloatingActionButton.Behavior {
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dx, int dy, int[] consumed) {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
if (dy > 0) {
child.hide();
} else {
child.show();
}
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) {
return true;
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。