您好,我知道这是一个重复的问题,但我无法从其他线程找到解决方案。
这就是我的问题,我有一个底部导航栏有五个片段的应用程序。我想通过应用程序快捷方式打开这些片段。
这是我所创造的,
shortcut.xml
<shortcuts xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="first"
android:enabled="true"
android:icon="@drawable/shortcut_1"
android:shortcutShortLabel="@string/shortcut_short_label_one"
android:shortcutLongLabel="@string/shortcut_long_label_one"
tools:targetApi="n_mr1">
<intent
android:action="com.xxxxxxx.xxxx.FIRST"
android:targetPackage="com.xxxxxxx.xxxx.test"
android:targetClass="com.xxxxxxx.xxxx.test.MainActivity" />
</shortcut>
<!-- Specify more shortcuts here. -->
<shortcut
android:shortcutId="second"
android:enabled="true"
android:icon="@drawable/shortcut_2"
android:shortcutShortLabel="@string/shortcut_short_label_two"
android:shortcutLongLabel="@string/shortcut_long_label_two"
tools:targetApi="n_mr1">
<intent
android:action="com.xxxxxxx.SECOND"
android:targetPackage="com.xxxxxxx.xxxx.test"
android:targetClass="com.xxxxxxx.xxxx.test.SecondFragment" />
</shortcut>
</shortcut>
下面是来自MainActivity的onCreate()
private static final String Second = "com.xxxxxxx.xxxx.SECOND";
//code vomited
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Second.equals(getIntent().getAction())){
SecondFragment secondFragment = new SecondFragment();
android.support.v4.app.FragmentTransaction fragmentTransactionTwo = getSupportFragmentManager().beginTransaction();
fragmentTransactionTwo.replace(R.id.content_main, secondFragment, "Fragment two");
fragmentTransactionTwo.commit();
}
BottomNavigationView navigation = findViewById(R.id.navigation);
BottomNavigationViewHelper.disableShiftMode(navigation); //disabling the shitty shifting mode
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
FirstFragment firstFragment = new FirstFragment();
android.support.v4.app.FragmentTransaction fragmentTransactionOne = getSupportFragmentManager().beginTransaction();
fragmentTransactionOne.replace(R.id.content_main, firstFragment, "Fragment one");
fragmentTransactionOne.commit();
}
在这里,第一个活动启动fine,即MainActivity()
。但是点击第二个快捷键,什么也不会发生。
有人告诉我我做错了什么吗?
发布于 2020-07-02 14:52:46
我和你有同样的问题,我找到了如何移动到碎片。你应该开始行动了。把这个放到onCreate里,也许这会对你有帮助
if ("com.xxxxxxx.YourShortcutAction".equals(getIntent().getAction())) {
val fragment = YourFragment()
addFragment(fragment)
}
我正在使用kotlin for android
https://stackoverflow.com/questions/50778003
复制相似问题