本文整理了Java中android.app.Activity.setActionBar()
方法的一些代码示例,展示了Activity.setActionBar()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.setActionBar()
方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:setActionBar
暂无
代码示例来源:origin: JessYanCoding/ArmsComponent
@Override
public void onActivityStarted(Activity activity) {
Timber.i(activity + " - onActivityStarted");
if (!activity.getIntent().getBooleanExtra("isInitToolbar", false)) {
//由于加强框架的兼容性,故将 setContentView 放到 onActivityCreated 之后,onActivityStarted 之前执行
//而 findViewById 必须在 Activity setContentView() 后才有效,所以将以下代码从之前的 onActivityCreated 中移动到 onActivityStarted 中执行
activity.getIntent().putExtra("isInitToolbar", true);
//这里全局给Activity设置toolbar和title,你想象力有多丰富,这里就有多强大,以前放到BaseActivity的操作都可以放到这里
if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar") != null) {
if (activity instanceof AppCompatActivity) {
((AppCompatActivity) activity).setSupportActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
((AppCompatActivity) activity).getSupportActionBar().setDisplayShowTitleEnabled(false);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.setActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
activity.getActionBar().setDisplayShowTitleEnabled(false);
}
}
}
if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title") != null) {
((TextView) ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title")).setText(activity.getTitle());
}
if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back") != null) {
ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back").setOnClickListener(v -> {
activity.onBackPressed();
});
}
}
}
代码示例来源:origin: iqiyi/Neptune
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void setActionBar(android.widget.Toolbar toolbar0) {
mOriginActivity.setActionBar(toolbar0);
}
代码示例来源:origin: noterpopo/Hands-Chopping
@Override
public void onActivityStarted(Activity activity) {
Timber.w(activity + " - onActivityStarted");
if (!activity.getIntent().getBooleanExtra("isInitToolbar", false)) {
//由于加强框架的兼容性,故将 setContentView 放到 onActivityCreated 之后,onActivityStarted 之前执行
//而 findViewById 必须在 Activity setContentView() 后才有效,所以将以下代码从之前的 onActivityCreated 中移动到 onActivityStarted 中执行
activity.getIntent().putExtra("isInitToolbar", true);
//这里全局给Activity设置toolbar和title,你想象力有多丰富,这里就有多强大,以前放到BaseActivity的操作都可以放到这里
if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar") != null) {
if (activity instanceof AppCompatActivity) {
((AppCompatActivity) activity).setSupportActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
((AppCompatActivity) activity).getSupportActionBar().setDisplayShowTitleEnabled(false);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.setActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
activity.getActionBar().setDisplayShowTitleEnabled(false);
}
}
}
if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title") != null) {
((TextView) ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title")).setText(activity.getTitle());
}
if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back") != null) {
ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back").setOnClickListener(v -> {
activity.onBackPressed();
});
}
}
}
代码示例来源:origin: limboemu/limbo
public static void setupToolBar(Activity activity) {
Toolbar tb = (Toolbar) activity.findViewById(R.id.toolbar);
activity.setActionBar(tb);
// Get the ActionBar here to configure the way it behaves.
final ActionBar ab = activity.getActionBar();
ab.setHomeAsUpIndicator(R.drawable.limbo); // set a custom icon for
// the
// default home button
ab.setDisplayShowHomeEnabled(true); // show or hide the default home
// button
ab.setDisplayHomeAsUpEnabled(true);
ab.setDisplayShowCustomEnabled(true); // enable overriding the
// default
// toolbar layout
ab.setDisplayShowTitleEnabled(true); // disable the default title
// element here (for
// centered
// title)
ab.setTitle(R.string.app_name);
if(!LimboSettingsManager.getAlwaysShowMenuToolbar(activity)){
ab.hide();
}
}
代码示例来源:origin: wasdennnoch/AndroidN-ify
mDrawerLayout = (DrawerLayout) inflater.inflate(ResourceUtils.getInstance(activity).getLayout(R.layout.settings_with_drawer), content, false);
Toolbar toolbar = (Toolbar) mDrawerLayout.findViewById(R.id.action_bar);
activity.setActionBar(toolbar);
ActionBar actionBar = activity.getActionBar();
actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
内容来源于网络,如有侵权,请联系作者删除!