- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个基于 fragment 的布局,其中包含两个 ListFragment(A 和 B),它们都包含在一个 Activity (称为 ListingActivity 1)中。当应用程序启动时,将调用 ListingActivity 1,并根据设备是纵向还是横向,仅显示 ListFragment A 或同时显示 ListFragment。
当您点击 Fragment A 的 ListView 中的项目时,Fragment B 的 ListView 随即显示。当您单击 Fragment B 的 ListView 中的项目时,它会转到新 Activity ( Activity 1)。
我正在使用此代码(称为 ListingActivity 2)来确定是单独显示 ListFragment B 还是与 ListFragment A 一起显示:
public class ListingActivity extends SherlockFragmentActivity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
// If the screen is now in landscape mode, we can show the
// dialog in-line so we don't need this activity.
finish();
return;
}
if (savedInstanceState == null) {
// During initial setup, plug in the details fragment.
final ListingFragment details = new ListingFragment();
details.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction().add(android.R.id.content, details).commit();
}
}
}
在 Activity 1 中,我使用 setDisplayHomeAsUpEnabled
将 Actionbar Logo 启用为后退按钮,但我不确定如何处理主页 Intent 。当设备处于纵向模式时,用户应返回到 ListingActivity 2,但如果设备处于横向模式,则应返回到 ListingActivity 1。
我本来打算做这样的事情,但它看起来真的很老套:
@Override
public boolean onOptionsItemSelected(final MenuItem item)
{
if (item.getItemId() == android.R.id.home)
{
final Intent intent;
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
intent = new Intent(this, ListingActivity1.class);
else
intent = new Intent(this, ListingActivity2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
最佳答案
老实说,我认为您的解决方案是实现所描述行为的正确方法。它遵守所有关于向上导航的 Android 标准(在这种情况下,它应该像“后退”按钮一样,我相信)。我唯一要重新考虑的是您对 Intent.FLAG_ACTIVITY_NEW_TASK
标志的使用。来自 Android 文档:
A task is the sequence of activities a user follows to accomplish a goal.
在这种情况下,您似乎并没有开始一项新任务。
关于android - 使用 fragment 处理 setDisplayHomeAsUpEnabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10264838/
我的应用程序每次崩溃,错误为 java.lang.RuntimeException: Unable to start Activity ComponentInfo{sidssol.com.bit_ta
在使用 AppCompatActivity 时是否可以指定 getSupportActionBar().setDisplayHomeAsUpEnabled(true) 使用样式,而不是以编程方式这样做
我想在我的 Activity 中显示向上按钮,该功能运行良好,但无法显示左插入符号。相反,它显示了一个丑陋的后退箭头。我在我的 Activity 中这样做 - public class SecondA
我们可以在 Activity 上使用 setDisplayHomeAsUpEnabled() 方法在操作栏上显示“向上”箭头。 如果我没理解错的话,只有当我们不是根 Activity 时,我们才真正应
我的应用程序使用 android.support.v7.app.ActionBar 以便我可以在我的 Android 2.3.4 手机和使用 Android 4.4.2 的平板电脑上使用 Action
当我点击主页图标时,抽屉打开,然后立即将我带回之前的 Activity 。我相信 setDisplayHomeAsUpEnabled(true) 会干扰保持打开状态的操作栏抽屉。 代码中是否有任何内容
在我扩展 SherlockFragmentActivity 的 Activity 中,我有操作栏并且还设置了 actionBar.setDisplayHomeAsUpEnabled(true) 以返回
根据 Google's document , getActionBar().setDisplayHomeAsUpEnabled(true) 需要显示向上按钮。我使用 Eclipse 中的向导创建了一个
我使用 setDisplayHomeAsUpEnabled 来显示箭头而不是抽屉“汉堡”图标,但它没有动画或任何东西。相反,它会立即显示可绘制的箭头。 主屏幕:(专辑 1) 点击电影时:(专辑 2)
首先,我知道这个问题之前已经被问过,我花了一个小时查看其他解决方案,大部分来自 - getActionBar() returns null ,但没有一个有效,因此另一双眼睛也许能够做一些事情。 其他类
这个问题已经有答案了: The getActionBar method returns null [duplicate] (1 个回答) 已关闭 8 年前。 应用程序不断崩溃。它说在actionBar
我正在使用 Android Studios,但是,我无法添加以下两种方法,因为它说它无法解析它们。 getSupportActionBar().setDisplayHomeAsUpEnabled(t
当我按下工具栏中的“后退/向上”按钮上升一级时,父 Activity 正在重新创建自身(重新加载数据等),而我只想完成 当前 Activity 。 现在我的 Activity 正在自动创建 Toolb
我是编码新手..练习一些教程..我已经研究过其他有类似问题的问题..但我无法解决它... 来自 mainActivity 的代码.. package example.org.myfragment; i
package com.maya.helloandroid; import java.util.ArrayList; import android.app.Activity; import andro
当我单击它按预期工作的图标时, list 中的所有内容都已正确设置,但是 ActionBar 上未显示 <箭头。有什么想法吗? actionBar.setDisplayHomeAsUpEnabled(
我调用了 setDisplayHomeAsUpEnabled(true) 并显示了箭头,但它没有指向任何地方,我还想手动设置按钮的链接/目标以转到自定义位置。 如何指定自定义位置?谢谢。 谢谢 最佳答
我有一个 SettingsActivity,它扩展了 PreferenceActivity 以显示我的应用中的设置。 有一个后退箭头,但它不起作用。 这是 SettingsActivity.java
我想在我的应用程序中的所有 Activity 的操作栏中添加应用程序图标,点击图标,我想导航到我的应用程序的主页。 我尝试在 onCreate 中使用以下代码 ActionBar actionBar
我有一个基于 fragment 的布局,其中包含两个 ListFragment(A 和 B),它们都包含在一个 Activity (称为 ListingActivity 1)中。当应用程序启动时,将调
我是一名优秀的程序员,十分优秀!