下面列出了androidx.appcompat.app.ActionBar#setHomeButtonEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle(R.string.settings_name);
}
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings_container, new RtspPreferenceFragment())
.commit();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle(R.string.settings_name);
}
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings_container, new RtspPreferenceFragment())
.commit();
}
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity == null) {
return;
}
setHasOptionsMenu(false);
ActionBar bar = activity.getSupportActionBar();
if (bar != null) {
bar.setDisplayHomeAsUpEnabled(true);
bar.setHomeButtonEnabled(true);
bar.setTitle(R.string.settings);
}
addPreferencesFromResource(R.xml.login_preferences);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
onSharedPreferenceChanged(sharedPreferences, "pref_hostName");
onSharedPreferenceChanged(sharedPreferences, "pref_useTLS");
onSharedPreferenceChanged(sharedPreferences, "pref_wireTransport");
}
/**
* 将Toolbar高度填充到状态栏
*/
public static void initFullBar(Toolbar toolbar, AppCompatActivity activity) {
ViewGroup.LayoutParams params = toolbar.getLayoutParams();
params.height = DensityUtil.getStatusHeight(activity) + getSystemActionBarSize(activity);
toolbar.setLayoutParams(params);
toolbar.setPadding(
toolbar.getLeft(),
toolbar.getTop() + DensityUtil.getStatusHeight(activity),
toolbar.getRight(),
toolbar.getBottom()
);
activity.setSupportActionBar(toolbar);
ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
private void setupActionBar() {
setSupportActionBar(binding.toolbar);
final ActionBar actionbar = requireActionBar();
final boolean displayUpButton = !isTaskRoot();
actionbar.setHomeButtonEnabled(displayUpButton);
actionbar.setDisplayHomeAsUpEnabled(displayUpButton);
}
@TargetApi(11)
@Override
public void holographic(AppCompatActivity a) {
ActionBar bar = a.getSupportActionBar();
if (bar != null) {
bar.setHomeButtonEnabled(true);
}
}
private void refreshActionBar(String title) {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(title);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
private void initActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
}
public void setupActionBar() {
if (mToolbarEnabled) {
setupToolbar();
} else {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
}
}
/**
* 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);
}
private void refreshActionBar(String title) {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(title);
actionBar.setHomeButtonEnabled(true);
if (mCurrentFragment instanceof SettingsFragment) {
actionBar.setDisplayHomeAsUpEnabled(false);
} else {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
}
private ActionBar setupActionBar() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(toolbar);
final ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
return actionBar;
}
@Deprecated
public void setupActionBar(Toolbar toolbar) {
if (toolbar != null && getSupportActionBar() == null) {
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
}
}
private void setupToolbar() {
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
static void setActionBarOptions(ActionBar actionBar) {
if (actionBar == null) {
return;
}
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
protected void setUpToolbar(Toolbar toolbar) {
toolbar.setTitle(getFragmentTitle());
setActivitySupportActionBar(toolbar);
ActionBar actionBar = getActivitySupportActionBar();
if (actionBar != null) {
boolean showUpButton = canNavigateUp();
actionBar.setDisplayHomeAsUpEnabled(showUpButton);
actionBar.setHomeButtonEnabled(showUpButton);
actionBar.setDisplayShowHomeEnabled(showUpButton);
actionBar.setHomeAsUpIndicator(getUpButtonDrawable());
}
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(true);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
setTitle(R.string.preferences);
}
super.onCreate(savedInstanceState);
}
private void setActionBarUpIndicator(Drawable drawable) {
ActionBarDrawerToggle.Delegate delegate = getDrawerToggleDelegate();
if (delegate != null) {
delegate.setActionBarUpIndicator(drawable, 0);
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
}
private void prepareActionBar(Toolbar toolbar) {
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
}