下面列出了androidx.appcompat.app.ActionBar#setDisplayShowHomeEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
MessagePostParam postParam = getMessagePostParam();
if (postParam.getAction().equals("new")) {
setTitle(R.string.new_message);
} else if (postParam.getAction().equals("reply")) {
setTitle(R.string.reply_message);
}
Bundle bundle = new Bundle();
bundle.putParcelable("param", postParam);
Fragment fragment = new MessagePostFragment();
fragment.setArguments(bundle);
fragment.setHasOptionsMenu(true);
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layoutRes());
toolbar = findViewById(R.id.toolbar);
ImageView icon = findViewById(R.id.icon);
slogan = findViewById(R.id.slogan);
version = findViewById(R.id.version);
collapsingToolbar = findViewById(R.id.collapsing_toolbar);
headerContentLayout = findViewById(R.id.header_content_layout);
onTitleViewCreated(collapsingToolbar);
onCreateHeader(icon, slogan, version);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
onApplyPresetAttrs();
recyclerView = findViewById(R.id.list);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(android.R.id.content);
if (fragment == null) {
fragment = new RecentNotificationFragment();
fragment.setArguments(getIntent().getExtras());
fm.beginTransaction().add(android.R.id.content, fragment).commit();
}
setTitle("我的被喷");
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
}
/**
* Show an up button in Collapsing Toolbar
*/
private void showUpButton() {
setSupportActionBar(mDetailBinding.toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
}
private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setTitle("");
}
}
private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setTitle("");
}
}
private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setTitle("");
}
}
private void setActionBarBack() {
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
private void setActionBarBack() {
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setTitle("");
}
}
@Override
protected void onResume() {
super.onResume();
ActionBar bar = getSupportActionBar();
if (null != bar) {
bar.setDisplayHomeAsUpEnabled(true); // 设置返回按钮可见
bar.setDisplayShowHomeEnabled(true); // 设置是否显示logo图标
bar.setHomeButtonEnabled(true); // 设置左上角的图标可点击
}
}
@Override
protected void onResume() {
super.onResume();
ActionBar bar = getSupportActionBar();
if (null != bar) {
bar.setDisplayHomeAsUpEnabled(true); // 设置返回按钮可见
bar.setDisplayShowHomeEnabled(true); // 设置是否显示logo图标
bar.setHomeButtonEnabled(true); // 设置左上角的图标可点击
}
}
private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setTitle("");
}
}
private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setTitle("");
}
}
private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setTitle("");
}
}
public View onActionBarCustom(AppCompatActivity a, int id) {
System.out.println("Setting custom ActionBar view");
ActionBar bar = a.getSupportActionBar();
if(bar == null){
return null;
}
bar.setDisplayShowCustomEnabled(true);
bar.setDisplayShowTitleEnabled(false);
bar.setDisplayShowHomeEnabled(true);
bar.setCustomView(id);
return bar.getCustomView();
}
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());
}
}
private void setupToolbar(Toolbar toolbar) {
toolbar.setTitle(mAlbum.getAlbumName());
setActivitySupportActionBar(toolbar);
ActionBar actionBar = getActivitySupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
}
private void setUpToolbar(Toolbar toolbar) {
toolbar.setTitle(mArtist.getArtistName());
setActivitySupportActionBar(toolbar);
ActionBar actionBar = getActivitySupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
}
}