androidx.appcompat.widget.Toolbar.setNavigationIcon()方法的使用及代码示例

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

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

Toolbar.setNavigationIcon介绍

暂无

代码示例

代码示例来源:origin: ankidroid/Anki-Android

mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
  @Override

代码示例来源:origin: alexvasilkov/GestureViews

/**
 * Initializing top image expanding animation.
 */
private void initTopImage() {
  views.fullImageToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
  views.fullImageToolbar.setNavigationOnClickListener(view -> onBackPressed());
  imageAnimator = GestureTransitions.from(views.appBarImage).into(views.fullImage);
  // Setting up and animating image transition
  imageAnimator.addPositionUpdateListener(this::applyFullImageState);
  views.appBarImage.setOnClickListener(view -> {
    getSettingsController().apply(views.fullImage);
    imageAnimator.enterSingle(true);
  });
}

代码示例来源:origin: KeepSafe/TapTargetView

toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_arrow_back_white_24dp));

代码示例来源:origin: alexvasilkov/GestureViews

/**
 * Initializing pager and fullscreen mode.
 */
private void initPager() {
  // Setting up pager adapter
  pagerAdapter = new PhotoPagerAdapter(views.pager, getSettingsController());
  pagerListener = new ViewPager.SimpleOnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {
      onPhotoInPagerSelected(position);
    }
  };
  views.pager.setAdapter(pagerAdapter);
  views.pager.addOnPageChangeListener(pagerListener);
  views.pager.setPageTransformer(true, new DepthPageTransformer());
  // Setting up pager toolbar
  views.pagerToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
  views.pagerToolbar.setNavigationOnClickListener(view -> onBackPressed());
  // Enabling immersive mode by clicking on full screen image
  pagerAdapter.setImageClickListener(() -> {
    if (!listAnimator.isLeaving()) {
      // Toggle immersive mode
      showSystemUi(!isSystemUiShown());
    }
  });
  getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
      visibility -> views.pagerToolbar.animate().alpha(isSystemUiShown() ? 1f : 0f));
}

代码示例来源:origin: ZieIony/Carbon

private void initLayout() {
  inflate(getContext(), R.layout.carbon_toolbar, this);
  super.setNavigationIcon(null);
  super.setTitle(null);
  content = findViewById(R.id.carbon_toolbarContent);
  title = findViewById(R.id.carbon_toolbarTitle);
  icon = findViewById(R.id.carbon_toolbarIcon);
  icon.setOnClickListener(view -> {
    if (getContext() == null)
      return;
    Context context = getContext();
    while (!(context instanceof Activity))
      context = ((ContextWrapper) context).getBaseContext();
    if (context instanceof UpAwareActivity) {
      ((UpAwareActivity) context).onUpPressed();
    } else {
      ((Activity) context).onBackPressed();
    }
  });
}

代码示例来源:origin: chrisbanes/PhotoView

toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
  @Override

代码示例来源:origin: michael-rapp/ChromeLikeTabSwitcher

/**
 * Adapts the navigation icon of the toolbar, which is shown, when the tab switcher is shown.
 */
private void adaptToolbarNavigationIcon() {
  Toolbar[] toolbars = getToolbars();
  if (toolbars != null) {
    Toolbar toolbar = toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX];
    Drawable icon = style.getToolbarNavigationIcon();
    toolbar.setNavigationIcon(icon);
    toolbar.setNavigationOnClickListener(getModel().getToolbarNavigationIconListener());
  }
}

代码示例来源:origin: iTXTech/Daedalus

Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(wrappedDrawable, Color.WHITE);
toolbar.setNavigationIcon(drawable);
toolbar.setNavigationOnClickListener(v -> onBackPressed());
toolbar.setOnMenuItemClickListener(fragment);

代码示例来源:origin: PureWriter/about-page

public void setNavigationIcon(@NonNull Drawable drawable) {
  toolbar.setNavigationIcon(drawable);
}

代码示例来源:origin: PureWriter/about-page

/**
 * Set the icon to use for the toolbar's navigation button.
 *
 * @param resId Resource ID of a drawable to set
 */
public void setNavigationIcon(@DrawableRes int resId) {
  toolbar.setNavigationIcon(resId);
}

代码示例来源:origin: linkedin/shaky-android

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  Toolbar toolbar = (Toolbar) view.findViewById(R.id.shaky_toolbar);
  EditText messageEditText = (EditText) view.findViewById(R.id.shaky_form_message);
  ImageView attachmentImageView = (ImageView) view.findViewById(R.id.shaky_form_attachment);
  Uri screenshotUri = getArguments().getParcelable(KEY_SCREENSHOT_URI);
  String title = getArguments().getString(KEY_TITLE);
  toolbar.setTitle(title);
  toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
  toolbar.setNavigationOnClickListener(createNavigationClickListener());
  toolbar.inflateMenu(R.menu.shaky_feedback_activity_actions);
  toolbar.setOnMenuItemClickListener(createMenuClickListener(messageEditText));
  String hint = getArguments().getString(KEY_HINT);
  messageEditText.setHint(hint);
  messageEditText.requestFocus();
  attachmentImageView.setImageURI(screenshotUri);
  attachmentImageView.setOnClickListener(createNavigationClickListener());
}

代码示例来源:origin: LineageOS/android_packages_apps_Jelly

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_settings);
  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  toolbar.setNavigationIcon(R.drawable.ic_back);
  toolbar.setNavigationOnClickListener(v -> finish());
}

代码示例来源:origin: pranavpandey/dynamic-support

/**
 * Set the icon and on click listener for the back or up button in the app bar.
 *
 * @param icon The drawable used for the back or up button.
 * @param onClickListener The click listener for the back or up button.
 */
public void setNavigationClickListener(@Nullable Drawable icon,
    @Nullable View.OnClickListener onClickListener) {
  mToolbar.setNavigationIcon(icon);
  setSupportActionBar(mToolbar);
  final ActionBar actionBar = getSupportActionBar();
  if (actionBar != null) {
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setHomeButtonEnabled(onClickListener != null);
  }
  mToolbar.setNavigationOnClickListener(onClickListener);
}

代码示例来源:origin: Commit451/AdapterLayout

toolbar = findViewById(R.id.toolbar);
adapterFlowLayout = findViewById(R.id.adapter_layout);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
  @Override

代码示例来源:origin: linkedin/shaky-android

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  FeedbackTypeAdapter adapter = new FeedbackTypeAdapter(getActivity(), getData());
  RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.shaky_recyclerView);
  recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
  recyclerView.setAdapter(adapter);
  Toolbar toolbar = (Toolbar) view.findViewById(R.id.shaky_toolbar);
  toolbar.setTitle(R.string.shaky_feedback_title);
  toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
  toolbar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      getActivity().onBackPressed();
    }
  });
}

代码示例来源:origin: AndroidDeveloperLB/MaterialPreferenceLibrary

@SuppressWarnings("deprecation")
@Override
protected void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.mpl__preference_activity);
  _toolbar = (Toolbar) findViewById(R.id.abp__toolbar);
  if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
    View shadowView = findViewById(R.id.abp__shadowView);
    final ViewGroup parent = (ViewGroup) shadowView.getParent();
    parent.removeView(shadowView);
  }
  addPreferencesFromResource(getPreferencesXmlId());
  final Map<Preference, PreferenceGroup> preferenceToParentMap = buildPreferenceParentTree(this);
  for (PreferenceGroup preferenceGroup : preferenceToParentMap.values())
    if (preferenceGroup instanceof PreferenceScreen)
      preferenceGroup.setLayoutResource(R.layout.mpl__preference);
  _toolbar.setClickable(true);
  _toolbar.setNavigationIcon(getResIdFromAttribute(this, R.attr.homeAsUpIndicator));
  _toolbar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(final View v) {
      finish();
    }
  });
  _toolbar.setTitle(getTitle());
}

代码示例来源:origin: cbeyls/fosdem-companion-android

/**
 * Initialize event-related configuration after the event has been loaded.
 */
private void initEvent(@NonNull Event event) {
  this.event = event;
  // Enable up navigation only after getting the event details
  toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
  toolbar.setNavigationContentDescription(R.string.abc_action_bar_up_description);
  toolbar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      navigateUp();
    }
  });
  final Track.Type trackType = event.getTrack().getType();
  ThemeUtils.setStatusBarTrackColor(this, trackType);
  final ColorStateList trackColor = ContextCompat.getColorStateList(this, trackType.getColorResId());
  appBarLayout.setBackgroundColor(trackColor.getDefaultColor());
  bottomAppBar.setBackgroundTint(trackColor);
  bookmarkStatusViewModel.setEvent(event);
  // Enable Android Beam
  NfcUtils.setAppDataPushMessageCallbackIfAvailable(this, this);
}

代码示例来源:origin: MCMrARM/revolution-irc

public ActionBarDrawerToggle(Toolbar toolbar, LockableDrawerLayout drawerLayout,
               int openTextId, int closeTextId) {
  mDrawable = new DrawerArrowDrawable(toolbar.getContext());
  mToolbar = toolbar;
  mOpenTextId = openTextId;
  mCloseTextId = closeTextId;
  drawerLayout.addDrawerListener(this);
  toolbar.setNavigationIcon(mDrawable);
  toolbar.setNavigationContentDescription(drawerLayout.isDrawerOpen(Gravity.START)
      ? closeTextId : openTextId);
  toolbar.setNavigationOnClickListener((View view) -> {
    if (drawerLayout.isDrawerOpen(Gravity.START))
      drawerLayout.closeDrawer(Gravity.START, !drawerLayout.isCurrentlyLocked());
    else
      drawerLayout.openDrawer(Gravity.START, !drawerLayout.isCurrentlyLocked());
    drawerLayout.requestLayout();
  });
  mOpenTextId = openTextId;
  mCloseTextId = closeTextId;
}

代码示例来源:origin: LineageOS/android_packages_apps_Jelly

toolbar.setNavigationIcon(R.drawable.ic_back);
toolbar.setNavigationOnClickListener(v -> finish());

代码示例来源:origin: LineageOS/android_packages_apps_Jelly

toolbar.setNavigationIcon(R.drawable.ic_back);
toolbar.setNavigationOnClickListener(v -> finish());

相关文章