本文整理汇总了Java中android.view.MenuItem.setCheckable方法的典型用法代码示例。如果您正苦于以下问题:Java MenuItem.setCheckable方法的具体用法?Java MenuItem.setCheckable怎么用?Java MenuItem.setCheckable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MenuItem
的用法示例。
在下文中一共展示了MenuItem.setCheckable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendFragments
import android.view.MenuItem; //导入方法依赖的package包/类
private void appendFragments(boolean setShortcuts) {
sActualFragments.clear();
Menu menu = mNavigationView.getMenu();
menu.clear();
SubMenu lastSubMenu = null;
for (NavigationFragment navigationFragment : sFragments) {
Fragment fragment = navigationFragment.mFragment;
int id = navigationFragment.mId;
Drawable drawable = ContextCompat.getDrawable(this,
Utils.DONATED
&& Prefs.getBoolean("section_icons", true, this)
&& navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable :
R.drawable.ic_blank);
if (fragment == null) {
lastSubMenu = menu.addSubMenu(id);
sActualFragments.put(id, null);
} else if (Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled",
true, this)) {
MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) :
lastSubMenu.add(0, id, 0, id);
menuItem.setIcon(drawable);
menuItem.setCheckable(true);
if (mSelection != 0) {
mNavigationView.setCheckedItem(mSelection);
}
sActualFragments.put(id, fragment);
}
}
if (setShortcuts) {
setShortcuts();
}
}
示例2: appendFragments
import android.view.MenuItem; //导入方法依赖的package包/类
private void appendFragments(boolean setShortcuts) {
sActualFragments.clear();
Menu menu = mNavigationView.getMenu();
menu.clear();
SubMenu lastSubMenu = null;
for (NavigationFragment navigationFragment : sFragments) {
Fragment fragment = navigationFragment.mFragment;
int id = navigationFragment.mId;
Drawable drawable = ContextCompat.getDrawable(this,
Utils.DONATED
&& Prefs.getBoolean("section_icons", false, this)
&& navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable :
R.drawable.ic_blank);
if (fragment == null) {
lastSubMenu = menu.addSubMenu(id);
sActualFragments.put(id, null);
} else if (Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled",
true, this)) {
MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) :
lastSubMenu.add(0, id, 0, id);
menuItem.setIcon(drawable);
menuItem.setCheckable(true);
if (mSelection != 0) {
mNavigationView.setCheckedItem(mSelection);
}
sActualFragments.put(id, fragment);
}
}
if (setShortcuts) {
setShortcuts();
}
}
示例3: selectFontSize
import android.view.MenuItem; //导入方法依赖的package包/类
private void selectFontSize() {
final int defsize = webView.getSettings().getDefaultFontSize();
int minsize = webView.getSettings().getMinimumFontSize();
final float scale = getResources().getDisplayMetrics().density;
// Log.d("READER", "def " + defsize + " " + scale);
final PopupMenu sizemenu = new PopupMenu(this, findViewById(R.id.zoom_button));
for (int size=minsize; size<=36; size+=2) {
final int s = size;
MenuItem mi = sizemenu.getMenu().add(" "+size);
mi.setCheckable(true);
mi.setChecked(size==defsize);
mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
Log.d("READER", "def " + (defsize-s));
int scrolloffset = (int)(-webView.getScrollY()*(defsize - s)/scale/2.7);
Log.d("READER", "scrollby " + scrolloffset);
setFontSize(s);
//attempt to adjust the scroll to keep the same text position.
// needs much work
webView.scrollBy(0, scrolloffset);
sizemenu.dismiss();
return true;
}
});
}
sizemenu.show();
}
示例4: onNavigationItemSelected
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onNavigationItemSelected(final MenuItem menuItem) {
Menu menu = navigationView.getMenu();
for (int i = 0; i < menu.size(); i++) {
MenuItem mi = menu.getItem(i);
if (!(mi.getItemId() == menuItem.getItemId())) {
mi.setCheckable(false);
}
}
menuItem.setCheckable(true);
if (menuItem.getTitle().equals(getResources().getString(R.string.logout))) {
menuItem.setChecked(false);
} else {
menuItem.setChecked(true);
}
mNavItemId = menuItem.getItemId();
// allow some time after closing the drawer before performing real navigation
// so the user can see what is happening
drawerLayout.closeDrawer(GravityCompat.START);
drawerActionHandler.postDelayed(new Runnable() {
@Override
public void run() {
navigate(menuItem.getItemId());
}
}, DRAWER_CLOSE_DELAY_MS);
return true;
}
示例5: populateContextMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public void populateContextMenu(ContextMenu menu, AdapterView.AdapterContextMenuInfo acmi, int num)
{
try
{
if (readWriteAdapter)
{
menu.add(0, R.id.fman_action_refresh, 0, R.string.fman_refresh_title);
menu.add(0, R.id.fman_action_create_folder, 0, R.string.fman_create_folder_title);
if (num > 0)
{
menu.add(0, R.id.fman_action_rename, 0, R.string.fman_rename_title);
menu.add(0, R.id.fman_action_delete, 0, R.string.fman_delete_title);
}
}
MenuItem activeSort = null;
menu.add(0, R.id.fman_action_sort_by_name, 0, R.string.fman_sort_by_name);
if ((mode & MODE_SORTING) == SORT_NAME)
{
activeSort = menu.findItem(R.id.fman_action_sort_by_name);
}
menu.add(0, R.id.fman_action_sort_by_ext, 0, R.string.fman_sort_by_ext);
if ((mode & MODE_SORTING) == SORT_EXT)
{
activeSort = menu.findItem(R.id.fman_action_sort_by_ext);
}
menu.add(0, R.id.fman_action_sort_by_size, 0, R.string.fman_sort_by_size);
if ((mode & MODE_SORTING) == SORT_SIZE)
{
activeSort = menu.findItem(R.id.fman_action_sort_by_size);
}
menu.add(0, R.id.fman_action_sort_by_date, 0, R.string.fman_sort_by_date);
if ((mode & MODE_SORTING) == SORT_DATE)
{
activeSort = menu.findItem(R.id.fman_action_sort_by_date);
}
if (activeSort != null)
{
activeSort.setCheckable(true);
activeSort.setChecked(true);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}