android.support.v7.widget.Toolbar.inflateMenu()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中android.support.v7.widget.Toolbar.inflateMenu()方法的一些代码示例,展示了Toolbar.inflateMenu()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Toolbar.inflateMenu()方法的具体详情如下:
包路径:android.support.v7.widget.Toolbar
类名称:Toolbar
方法名:inflateMenu

Toolbar.inflateMenu介绍

暂无

代码示例

代码示例来源:origin: rey5137/material

/**
 * This funcction should be called in onCreateOptionsMenu of Activity or Fragment to inflate a new menu.
 * @param menuId
 */
public void createMenu(int menuId){
  mToolbar.inflateMenu(menuId);
  mMenuDataChanged = true;
  if(mAppCompatDelegate == null)
    onPrepareMenu();
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public boolean onCreateOptionsMenu(Menu menu) {
 Toolbar tb=(Toolbar)findViewById(R.id.toolbar);
 tb.inflateMenu(R.menu.actions);
 tb.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  @Override
  public boolean onMenuItemClick(MenuItem item) {
   return(onOptionsItemSelected(item));
  }
 });
 return(super.onCreateOptionsMenu(menu));
}

代码示例来源:origin: TeamNewPipe/NewPipe

private void initToolbar(Toolbar toolbar) {
  if (DEBUG) Log.d(TAG, "initToolbar() called with: toolbar = [" + toolbar + "]");
  toolbar.setTitle(R.string.download_dialog_title);
  toolbar.setNavigationIcon(ThemeHelper.isLightThemeSelected(getActivity()) ? R.drawable.ic_arrow_back_black_24dp : R.drawable.ic_arrow_back_white_24dp);
  toolbar.inflateMenu(R.menu.dialog_url);
  toolbar.setNavigationOnClickListener(v -> getDialog().dismiss());
  toolbar.setOnMenuItemClickListener(item -> {
    if (item.getItemId() == R.id.okay) {
      prepareSelectedDownload();
      return true;
    }
    return false;
  });
}

代码示例来源:origin: Cleveroad/AdaptiveTableLayout

toolbar.inflateMenu(R.menu.table_layout);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  @Override

代码示例来源:origin: square/spoon

@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 if (!getIntent().hasExtra(KEY_AMOUNT_CENTS)) {
  throw new IllegalStateException("Missing amount extra");
 }
 amount = getIntent().getLongExtra(KEY_AMOUNT_CENTS, -1);
 if (amount < 100) {
  throw new IllegalArgumentException("Invalid amount: " + amount);
 }
 setContentView(R.layout.recipeint);
 ButterKnife.bind(this);
 toolbar.setTitle(getString(R.string.send_amount, Moneys.formatCents(amount)));
 toolbar.inflateMenu(R.menu.recipient);
 sendMenuItem = toolbar.getMenu().findItem(R.id.recipient_send);
 sendMenuItem.setEnabled(false);
 toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  @Override public boolean onMenuItemClick(MenuItem item) {
   switch (item.getItemId()) {
    case R.id.recipient_send:
     onSendClicked();
     return true;
    default:
     throw new IllegalStateException("Unknown menu item: " + item);
   }
  }
 });
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

toolbar.inflateMenu(R.menu.news_detail);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  @Override

代码示例来源:origin: seven332/EhViewer

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  if (mToolbar != null) {
    if (mTempTitle != null) {
      mToolbar.setTitle(mTempTitle);
      mTempTitle = null;
    }
    int menuResId = getMenuResId();
    if (menuResId != 0) {
      mToolbar.inflateMenu(menuResId);
      mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
          return ToolbarScene.this.onMenuItemClick(item);
        }
      });
      onMenuCreated(mToolbar.getMenu());
    }
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        onNavigationClick();
      }
    });
  }
}

代码示例来源:origin: seven332/EhViewer

toolbar.inflateMenu(R.menu.drawer_download);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  @Override

代码示例来源:origin: pinguo-zhouwei/MZBannerView

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.home_activity);
  StatusBarUtils.setColor(this,getResources().getColor(R.color.colorPrimary),0);
  mToolbar = (Toolbar) findViewById(R.id.tool_bar);
  mToolbar.inflateMenu(R.menu.setting);
  mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if(item.getItemId() ==R.id.banner_mode){
        switchBannerMode();
      }else if(item.getItemId() == R.id.viewPager_mode){
        switchViewPagerMode();
      }else if(item.getItemId() == R.id.remote_mode){
        switchRemoteMode();
      }else if(item.getItemId() == R.id.mz_mode_not_cover){
        switchMZModeNotCover();
      }
      return true;
    }
  });
  Fragment fragment = MZModeBannerFragment.newInstance();
  getSupportFragmentManager().beginTransaction().add(R.id.home_container,fragment).commit();
}

代码示例来源:origin: seven332/EhViewer

toolbar.inflateMenu(R.menu.drawer_gallery_list);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  @Override

代码示例来源:origin: qiujuer/Genius-Android

private void initToolbar() {
  // ToolBar
  RipAnimDrawable ripAnim = new RipAnimDrawable();
  ripAnim.setColor(getResources().getColor(R.color.cyan_600));
  ripAnim.setFluCount(0, 0, 0, 36);
  Toolbar toolbar = (Toolbar) findViewById(R.id.title);
  toolbar.setBackgroundDrawable(ripAnim);
  toolbar.setTitle(getTitle());
  toolbar.inflateMenu(R.menu.menu_main);
  toolbar.setOnMenuItemClickListener(this);
}

代码示例来源:origin: seven332/EhViewer

toolbar.inflateMenu(R.menu.drawer_favorites);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  @Override

代码示例来源:origin: iMeiji/Toutiao

private void initView() {
  toolbar = findViewById(R.id.toolbar);
  toolbar.inflateMenu(R.menu.menu_activity_main);
  bottom_navigation = findViewById(R.id.bottom_navigation);
  BottomNavigationViewHelper.disableShiftMode(bottom_navigation);

代码示例来源:origin: TakWolf/CNode-Material-Design

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  ThemeUtils.configThemeBeforeOnCreate(this, R.style.AppThemeLight, R.style.AppThemeDark);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_modify_topic_sign);
  ButterKnife.bind(this);
  toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
  toolbar.inflateMenu(R.menu.modify_topic_sign);
  toolbar.setOnMenuItemClickListener(this);
  edtContent.setText(SettingShared.getTopicSignContent(this));
  edtContent.setSelection(edtContent.length());
}

代码示例来源:origin: TakWolf/CNode-Material-Design

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  ThemeUtils.configThemeBeforeOnCreate(this, R.style.AppThemeLight, R.style.AppThemeDark);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_crash_log);
  ButterKnife.bind(this);
  toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
  toolbar.inflateMenu(R.menu.crash_log);
  toolbar.setOnMenuItemClickListener(this);
  Throwable e = (Throwable) getIntent().getSerializableExtra(EXTRA_E);
  crashLog = "生产厂商:\n" +
      Build.MANUFACTURER + "\n\n" +
      "手机型号:\n" +
      Build.MODEL + "\n\n" +
      "系统版本:\n" +
      Build.VERSION.RELEASE + "\n\n" +
      "异常时间:\n" +
      new DateTime() + "\n\n" +
      "异常类型:\n" +
      e.getClass().getName() + "\n\n" +
      "异常信息:\n" +
      e.getMessage() + "\n\n" +
      "异常堆栈:\n" +
      Log.getStackTraceString(e);
  tvInfo.setText(crashLog);
}

代码示例来源:origin: TakWolf/CNode-Material-Design

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  ThemeUtils.configThemeBeforeOnCreate(this, R.style.AppThemeLight, R.style.AppThemeDark);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_notification_compat);
  ButterKnife.bind(this);
  toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
  toolbar.inflateMenu(R.menu.notification);
  toolbar.setOnMenuItemClickListener(this);
  toolbar.setOnClickListener(new DoubleClickBackToContentTopListener(webNotification));
  notificationPresenter = new NotificationPresenter(this, this);
  refreshLayout.setColorSchemeResources(R.color.color_accent);
  refreshLayout.setOnRefreshListener(this);
  refreshLayout.setRefreshing(true);
  onRefresh();
}

代码示例来源:origin: TakWolf/CNode-Material-Design

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  ThemeUtils.configThemeBeforeOnCreate(this, R.style.AppThemeLight, R.style.AppThemeDark);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_user_detail);
  ButterKnife.bind(this);
  ViewCompat.setTransitionName(imgAvatar, NAME_IMG_AVATAR);
  toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
  toolbar.inflateMenu(R.menu.user_detail);
  toolbar.setOnMenuItemClickListener(this);
  adapter = new UserDetailPagerAdapter(this, viewPager);
  viewPager.setAdapter(adapter);
  viewPager.setOffscreenPageLimit(adapter.getCount());
  tabLayout.setupWithViewPager(viewPager);
  loginName = getIntent().getStringExtra(EXTRA_LOGIN_NAME);
  tvLoginName.setText(loginName);
  String avatarUrl = getIntent().getStringExtra(EXTRA_AVATAR_URL);
  if (!TextUtils.isEmpty(avatarUrl)) {
    GlideApp.with(this).load(avatarUrl).placeholder(R.drawable.image_placeholder).into(imgAvatar);
  }
  userDetailPresenter = new UserDetailPresenter(this, this);
  userDetailPresenter.getUserAsyncTask(loginName);
}

代码示例来源:origin: TakWolf/CNode-Material-Design

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  ThemeUtils.configThemeBeforeOnCreate(this, R.style.AppThemeLight, R.style.AppThemeDark);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_notification);
  ButterKnife.bind(this);
  toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
  toolbar.inflateMenu(R.menu.notification);
  toolbar.setOnMenuItemClickListener(this);
  toolbar.setOnClickListener(new DoubleClickBackToContentTopListener(this));
  recyclerView.setLayoutManager(new LinearLayoutManager(this));
  adapter = new MessageListAdapter(this);
  recyclerView.setAdapter(adapter);
  notificationPresenter = new NotificationPresenter(this, this);
  refreshLayout.setColorSchemeResources(R.color.color_accent);
  refreshLayout.setOnRefreshListener(this);
  refreshLayout.setRefreshing(true);
  onRefresh();
}

代码示例来源:origin: TakWolf/CNode-Material-Design

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  ThemeUtils.configThemeBeforeOnCreate(this, R.style.AppThemeLight, R.style.AppThemeDark);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_create_topic);
  ButterKnife.bind(this);
  toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
  toolbar.inflateMenu(R.menu.create_topic);
  toolbar.setOnMenuItemClickListener(this);
  spnTab.setAdapter(new TabSpinnerAdapter(this, Tab.getPublishableTabList()));
  progressDialog = ProgressDialog.createWithAutoTheme(this);
  progressDialog.setCancelable(false);
  // 创建EditorBar
  new EditorBarViewHolder(this, editorBar, edtContent);
  // 载入草稿
  if (SettingShared.isEnableTopicDraft(this)) {
    spnTab.setSelection(TopicShared.getDraftTabPosition(this));
    edtContent.setText(TopicShared.getDraftContent(this));
    edtContent.setSelection(edtContent.length());
    edtTitle.setText(TopicShared.getDraftTitle(this));
    edtTitle.setSelection(edtTitle.length()); // 这个必须最后调用
  }
  createTopicPresenter = new CreateTopicPresenter(this, this);
}

代码示例来源:origin: TakWolf/CNode-Material-Design

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  ThemeUtils.configThemeBeforeOnCreate(this, R.style.AppThemeLight, R.style.AppThemeDark);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_topic_compat);
  ButterKnife.bind(this);
  topicId = getIntent().getStringExtra(Navigator.TopicWithAutoCompat.EXTRA_TOPIC_ID);
  toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
  toolbar.inflateMenu(R.menu.topic);
  toolbar.setOnMenuItemClickListener(this);
  toolbar.setOnClickListener(new DoubleClickBackToContentTopListener(this));
  topicPresenter = new TopicPresenter(this, this);
  topicHeaderPresenter = new TopicHeaderPresenter(this, this);
  replyPresenter = new ReplyPresenter(this, this);
  createReplyView = CreateReplyDialog.createWithAutoTheme(this, topicId, this);
  webTopic.addOnScrollListener(new FloatingActionButtonBehaviorListener.ForWebView(fabReply));
  webTopic.setBridgeAndLoadPage(new TopicJavascriptInterface(this, createReplyView, topicHeaderPresenter, replyPresenter));
  refreshLayout.setColorSchemeResources(R.color.color_accent);
  refreshLayout.setOnRefreshListener(this);
  refreshLayout.setRefreshing(true);
  onRefresh();
}

相关文章

Toolbar类方法