use of android.support.v4.widget.DrawerLayout in project Libraries-for-Android-Developers by eoecn.
the class MainActivity method onCreate.
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.common_title_bg));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer);
mContentLayout = (FrameLayout) findViewById(R.id.content_frame);
mDrawerList = (ListView) findViewById(R.id.left_drawer_list_view);
// List<Object> items = new ArrayList<Object>();
// items.add(new Category(""));
// items.add(new Item("最新的", R.drawable.star));
// items.add(new Item("热门的", R.drawable.like_me));
// items.add(new Item("收藏的", R.drawable.star));
//获取侧栏目数据 每次都更新不使用缓存
SlideFactory.getInstance(this).getSlide(false, new SlideRevHandler() {
@Override
public void onSuccess(int statusCode, LibSlides slides) {
//异步获取的,如果有缓存数据就直接返回
System.err.println(statusCode + " " + slides.getData().get(0).getItems().get(0).getTitle());
}
@Override
public void onFailure(int statusCode, Throwable throwable) {
throwable.printStackTrace();
}
});
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.app_name, /* "open drawer" description for accessibility */
R.string.app_name) {
/* "close drawer" description for accessibility */
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
// creates call to onPrepareOptionsMenu()
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
// creates call to onPrepareOptionsMenu()
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(0);
}
}
use of android.support.v4.widget.DrawerLayout in project ListenerMusicPlayer by hefuyicoder.
the class ColorUtil method setStatusBarColor.
public static void setStatusBarColor(Activity activity, int color) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final Window window = activity.getWindow();
window.setStatusBarColor(getStatusBarColor(color));
applyTaskDescription(activity, color);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final View decorView = activity.getWindow().getDecorView();
boolean lightStatusEnabled = isColorLight(color);
final int systemUiVisibility = decorView.getSystemUiVisibility();
if (lightStatusEnabled) {
decorView.setSystemUiVisibility(systemUiVisibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
decorView.setSystemUiVisibility(systemUiVisibility & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
}
((DrawerLayout) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0)).setStatusBarBackgroundColor(getStatusBarColor(color));
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.support.v4.widget.DrawerLayout in project UltimateAndroid by cymcsg.
the class NavigationDrawerFragment method setUp.
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
* @param fragmentId The android:id of this fragment in its activity's layout.
* @param drawerLayout The DrawerLayout containing this fragment's UI.
*/
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
ActionBar actionBar = getActivity().getActionBar();
// actionBar.setDisplayHomeAsUpEnabled(true);
// actionBar.setHomeButtonEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the navigation drawer and the action bar app icon.
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close) {
/* "close drawer" description for accessibility */
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) {
return;
}
// calls onPrepareOptionsMenu()
getActivity().invalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) {
return;
}
if (!mUserLearnedDrawer) {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit();
}
// calls onPrepareOptionsMenu()
getActivity().invalidateOptionsMenu();
}
};
// per the navigation drawer design guidelines.
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mDrawerToggle.syncState();
}
});
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
use of android.support.v4.widget.DrawerLayout in project EazeGraph by blackfizz.
the class NavigationDrawerFragment method setUp.
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
* @param fragmentId The android:id of this fragment in its activity's layout.
* @param drawerLayout The DrawerLayout containing this fragment's UI.
*/
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the navigation drawer and the action bar app icon.
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close) {
/* "close drawer" description for accessibility */
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) {
return;
}
// calls onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) {
return;
}
if (!mUserLearnedDrawer) {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit();
}
// calls onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
};
// per the navigation drawer design guidelines.
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mDrawerToggle.syncState();
}
});
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
use of android.support.v4.widget.DrawerLayout in project MaterialIntroView by iammert.
the class MainActivity method onNavigationItemSelected.
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
switch(item.getItemId()) {
case R.id.nav_demo:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new MainFragment()).commit();
break;
case R.id.nav_gravity:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new GravityFragment()).commit();
break;
case R.id.nav_focus:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new FocusFragment()).commit();
break;
case R.id.nav_recyclerview:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new RecyclerviewFragment()).commit();
break;
case R.id.nav_toolbar:
startActivity(new Intent(getApplicationContext(), ToolbarMenuItemActivity.class));
break;
case R.id.nav_tab:
break;
default:
break;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
Aggregations