本文整理汇总了Java中android.support.v4.view.GravityCompat类的典型用法代码示例。如果您正苦于以下问题:Java GravityCompat类的具体用法?Java GravityCompat怎么用?Java GravityCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GravityCompat类属于android.support.v4.view包,在下文中一共展示了GravityCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setDrawerShadow
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
/**
* Set a simple drawable used for the left or right shadow.
* The drawable provided must have a nonzero intrinsic width.
*
* @param shadowDrawable Shadow drawable to use at the edge of a drawer
* @param gravity Which drawer the shadow should apply to
*/
public void setDrawerShadow(Drawable shadowDrawable, @EdgeGravity int gravity) {
/*
* TODO Someone someday might want to set more complex drawables here.
* They're probably nuts, but we might want to consider registering callbacks,
* setting states, etc. properly.
*/
final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
ViewCompat.getLayoutDirection(this));
if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
mShadowLeft = shadowDrawable;
invalidate();
}
if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
mShadowRight = shadowDrawable;
invalidate();
}
}
示例2: onBackPressed
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
Fragment f = getSupportFragmentManager().findFragmentById(R.id.containerHome);
if (f instanceof MapFragment) {
super.onBackPressed();
} else {
if (getIntent().getExtras() != null && getIntent().getExtras().getString(EXTRA_DATA) != null) {
finish();
} else {
navigationView.getMenu().getItem(0).setChecked(true);
setTitleToolbar(getString(R.string.map_stations));
getSupportFragmentManager().popBackStack("", FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
}
}
}
示例3: RecyclerViewScrollbar
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
public RecyclerViewScrollbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.RecyclerViewScrollbar, defStyleAttr, 0);
mRecyclerViewId = ta.getResourceId(R.styleable.RecyclerViewScrollbar_recyclerView, 0);
mScrollbarDrawable = ta.getDrawable(R.styleable.RecyclerViewScrollbar_scrollbarDrawable);
mLetterDrawable = ta.getDrawable(R.styleable.RecyclerViewScrollbar_letterDrawable);
int letterTextResId = ta.getResourceId(R.styleable.RecyclerViewScrollbar_letterTextAppearance, 0);
mMinScrollbarHeight = ta.getDimensionPixelOffset(R.styleable.RecyclerViewScrollbar_minScrollbarHeight, 0);
ta.recycle();
mLetterView = new TextView(getContext());
mLetterView.setBackgroundDrawable(mLetterDrawable);
TextViewCompat.setTextAppearance(mLetterView, letterTextResId);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = GravityCompat.END;
mLetterView.setLayoutParams(params);
mLetterView.setGravity(Gravity.CENTER);
}
示例4: setupViewsForKey
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
public void setupViewsForKey(Key key, View newView) {
if(key.shouldShowUp()) {
setDrawerLockMode(LOCK_MODE_LOCKED_CLOSED, GravityCompat.START);
drawerToggle.setDrawerIndicatorEnabled(false);
MainActivity.get(getContext()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} else {
setDrawerLockMode(LOCK_MODE_UNLOCKED, GravityCompat.START);
MainActivity.get(getContext()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
drawerToggle.setDrawerIndicatorEnabled(true);
}
drawerToggle.syncState();
setCheckedItem(key.navigationViewId());
MainActivity.get(getContext()).supportInvalidateOptionsMenu();
if(key.isFabVisible()) {
fabAddTask.setVisibility(View.VISIBLE);
} else {
fabAddTask.setVisibility(View.GONE);
}
fabAddTask.setOnClickListener(key.fabClickListener(newView));
if(key.fabDrawableIcon() != 0) {
fabAddTask.setImageResource(key.fabDrawableIcon());
}
}
示例5: showIndicator
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
public void showIndicator(View parent, Rect touchBounds) {
if (isShowing()) {
mPopupView.mMarker.animateOpen();
return;
}
IBinder windowToken = parent.getWindowToken();
if (windowToken != null) {
WindowManager.LayoutParams p = createPopupLayout(windowToken);
p.gravity = Gravity.TOP | GravityCompat.START;
updateLayoutParamsForPosiion(parent, p, touchBounds.bottom);
mShowing = true;
translateViewIntoPosition(touchBounds.centerX());
invokePopup(p);
}
}
示例6: onBackPressed
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
// back to all groups
// super.onBackPressed();
if (statusToShow != null) {
Log.w("true", statusToShow.toString());
Intent intent = new Intent(this, UserGroupLessonsActivity.class);
startActivity(intent);
} else {
Log.w("false", "false");
super.onBackPressed();
}
}
}
示例7: onNavigationItemSelected
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_settings) {
} else if (id == R.id.nav_about) {
Intent intent = new Intent(this, OssLicensesMenuActivity.class);
String title = getString(R.string.license_screen_title);
intent.putExtra("title", title);
startActivity(intent);
return true;
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return super.onOptionsItemSelected(item);
}
示例8: applyModeAndGravity
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
private void applyModeAndGravity() {
int paddingStart = 0;
if (mMode == MODE_SCROLLABLE) {
// If we're scrollable, or fixed at start, inset using padding
paddingStart = Math.max(0, mContentInsetStart - mTabPaddingStart);
}
ViewCompat.setPaddingRelative(mTabStrip, paddingStart, 0, 0, 0);
switch (mMode) {
case MODE_FIXED:
mTabStrip.setGravity(Gravity.CENTER_HORIZONTAL);
break;
case MODE_SCROLLABLE:
mTabStrip.setGravity(GravityCompat.START);
break;
}
updateTabViews(true);
}
示例9: onNavigationItemSelected
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例10: onOptionsItemSelected
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.backup:
Toast.makeText(this, "well, you clicked Backup", Toast.LENGTH_SHORT).show();
break;
case R.id.about:
showToast("Software Copyright Reserved ");
break;
case android.R.id.home:
mDrawerLayout.openDrawer(GravityCompat.START);
break;
case R.id.settings: //写个新的activity关于
Intent intent1 = new Intent(this, SettingActivity.class);
startActivity(intent1);
break;
default:
break;
}
return true;
}
示例11: onNavigationItemSelected
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("active_switch", false)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
if (id == R.id.nav_map) {
itemSelected = 0;
setTitleToolbar(getString(R.string.map_stations));
getSupportFragmentManager().popBackStack("", FragmentManager.POP_BACK_STACK_INCLUSIVE);
} else {
if (checkIfItsLogged(id)) {
showFragment(id);
} else {
navigationView.getMenu().getItem(itemSelected).setChecked(true);
showLoginDialog();
}
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例12: onNavigationItemSelected
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_logout) {
editor.putString("user_id", null);
editor.putString("user_token", null);
editor.putString("user_name", null);
AppController.USER_ID = null;
AppController.USER_TOKEN = null;
AppController.USER_NAME = null;
editor.commit();
finish();
startActivity(new Intent(ActivityMain.this, ActivityLaunchScreen_.class));
}
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
示例13: onNavigationItemSelected
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
changePosts(POSTS_ACTIVE);
} else if (id == R.id.nav_archived) {
changePosts(POSTS_ARCHIVED);
} else if (id == R.id.nav_favourites) {
changePosts(POSTS_FAVOURITES);
} else if (id == R.id.nav_settings) {
startActivity(new Intent(App.getAppContext(),Settings.class));
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例14: toggle
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
private void toggle() {
int drawerLockMode = this.mDrawerLayout.getDrawerLockMode((int) GravityCompat.START);
if (this.mDrawerLayout.isDrawerVisible((int) GravityCompat.START) && drawerLockMode != 2) {
this.mDrawerLayout.closeDrawer((int) GravityCompat.START);
} else if (drawerLockMode != 1) {
this.mDrawerLayout.openDrawer((int) GravityCompat.START);
}
}
示例15: onBackPressed
import android.support.v4.view.GravityCompat; //导入依赖的package包/类
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}