use of android.support.v7.widget.Toolbar in project SwipeRecyclerView by yanzhenjie.
the class MenuVerticalActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
mContext = this;
mDataList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
mDataList.add("我是第" + i + "个菜单");
}
mMenuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
// 布局管理器。
mMenuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// 添加分割线。
mMenuRecyclerView.addItemDecoration(new ListViewDecoration());
// 为SwipeRecyclerView的Item创建菜单就两句话,不错就是这么简单:
// 设置菜单创建器。
mMenuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
// 设置菜单Item点击监听。
mMenuRecyclerView.setSwipeMenuItemClickListener(menuItemClickListener);
mMenuAdapter = new MenuVerticalAdapter(mDataList);
mMenuAdapter.setOnItemClickListener(onItemClickListener);
mMenuRecyclerView.setAdapter(mMenuAdapter);
}
use of android.support.v7.widget.Toolbar in project SwipeRecyclerView by yanzhenjie.
the class MenuViewTypeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
mContext = this;
// 这里只是模拟数据,模拟Item的ViewType,根据ViewType决定显示什么菜单,到时候你可以根据你的数据来决定ViewType。
mViewTypeBeanList = new ArrayList<>();
for (int i = 0, j = 0; i < 30; i++, j++) {
ViewTypeBean viewTypeBean = new ViewTypeBean();
if (j == 0) {
viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_NONE);
viewTypeBean.setContent("我没有菜单");
} else if (j == 1) {
viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_SINGLE);
viewTypeBean.setContent("我有1个菜单");
} else if (j == 2) {
viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_MULTI);
viewTypeBean.setContent("我有2个菜单");
} else if (j == 3) {
viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_LEFT);
viewTypeBean.setContent("我的左边有菜单,右边没有");
j = -1;
}
mViewTypeBeanList.add(viewTypeBean);
}
SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
menuRecyclerView.addItemDecoration(new ListViewDecoration());
menuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
menuRecyclerView.setSwipeMenuItemClickListener(menuItemClickListener);
MenuViewTypeAdapter menuAdapter = new MenuViewTypeAdapter(mViewTypeBeanList);
menuAdapter.setOnItemClickListener(onItemClickListener);
menuRecyclerView.setAdapter(menuAdapter);
}
use of android.support.v7.widget.Toolbar in project SwipeRecyclerView by yanzhenjie.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.set(10, 10, 10, 15);
}
});
List<String> titles = Arrays.asList(getResources().getStringArray(R.array.main_item));
List<String> descriptions = Arrays.asList(getResources().getStringArray(R.array.main_item_des));
MainItemAdapter mainItemAdapter = new MainItemAdapter(titles, descriptions);
mainItemAdapter.setOnItemClickListener(this);
recyclerView.setAdapter(mainItemAdapter);
}
use of android.support.v7.widget.Toolbar in project SwipeRecyclerView by yanzhenjie.
the class DragSwipeFlagsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mActionBar = getSupportActionBar();
assert mActionBar != null;
mActionBar.setDisplayHomeAsUpEnabled(true);
mDataList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
if (i == 0) {
mDataList.add("我不能被拖拽,也不能滑动删除。");
} else {
mDataList.add("我是第" + i + "个。");
}
}
SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
// 布局管理器。
menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// 添加分割线。
menuRecyclerView.addItemDecoration(new ListViewDecoration());
// 这个就不用添加菜单啦,因为滑动删除和菜单是冲突的。
mMenuAdapter = new MenuAdapter(mDataList);
mMenuAdapter.setOnItemClickListener(onItemClickListener);
menuRecyclerView.setAdapter(mMenuAdapter);
// 开启长安拖拽。
menuRecyclerView.setLongPressDragEnabled(true);
// 开启滑动删除。
menuRecyclerView.setItemViewSwipeEnabled(true);
// 监听拖拽,更新UI。
menuRecyclerView.setOnItemMoveListener(onItemMoveListener);
menuRecyclerView.setOnItemMovementListener(onItemMovementListener);
menuRecyclerView.setOnItemStateChangedListener(mOnItemStateChangedListener);
}
use of android.support.v7.widget.Toolbar in project TourGuide by worker8.
the class NavDrawerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivity = this;
setContentView(R.layout.activity_nav_drawer);
/* get views from xml */
mTextView1 = (TextView) findViewById(R.id.item1);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
/* setup toolbar */
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar.setTitle("Nav Drawer Example");
mTutorialHandler = TourGuide.init(mActivity).with(TourGuide.Technique.CLICK).setPointer(new Pointer()).setToolTip(new ToolTip().setTitle(null).setDescription("hello world")).setOverlay(new Overlay().setBackgroundColor(Color.parseColor("#66FF0000")));
final ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open_string, R.string.drawer_close_string) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
/* We need call playOn only after the drawer is opened,
so that TourGuide knows the updated location of the targetted view */
mTutorialHandler.playOn(mTextView1);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
/* setup clean up code */
mTextView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mTutorialHandler.cleanUp();
mDrawerLayout.closeDrawers();
}
});
final ViewTreeObserver viewTreeObserver = mTextView1.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// make sure this only run once
mTextView1.getViewTreeObserver().removeGlobalOnLayoutListener(this);
mDrawerLayout.openDrawer(Gravity.LEFT);
}
});
}
Aggregations