小编Sim*_*one的帖子

Android Jetpack导航,使用Youtube或Instagram的BottomNavigationView,如正确的后退导航(片段后退堆栈)?

Android Jetpack导航,BottomNavigationView在后退按钮上点击自动片段后栈?

我想要的是,在用户一个接一个地选择多个标签后,用户点击后退按钮应用必须重定向到他/她打开的最后一页.

通过在ArrayList中保存当前选定的项目,我使用Android ViewPager实现了相同的功能.Android Jetpack导航发布后是否有任何自动后退堆栈?我想用导航图实现它

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".main.MainActivity">

    <fragment
        android:id="@+id/my_nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@+id/navigation"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/nav_graph" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/navigation_home"
        android:icon="@drawable/ic_home"
        android:title="@string/title_home" />

    <item
        android:id="@+id/navigation_people"
        android:icon="@drawable/ic_group"
        android:title="@string/title_people" />

    <item
        android:id="@+id/navigation_organization"
        android:icon="@drawable/ic_organization"
        android:title="@string/title_organization" />

    <item
        android:id="@+id/navigation_business"
        android:icon="@drawable/ic_business"
        android:title="@string/title_business" />

    <item
        android:id="@+id/navigation_tasks"
        android:icon="@drawable/ic_dashboard"
        android:title="@string/title_tasks" />

</menu>
Run Code Online (Sandbox Code Playgroud)

还补充道

bottomNavigation.setupWithNavController(Navigation.findNavController(this, R.id.my_nav_host_fragment))
Run Code Online (Sandbox Code Playgroud)

我得到了一个答案Levi …

android android-navigation bottomnavigationview android-architecture-components android-architecture-navigation

50
推荐指数
7
解决办法
2万
查看次数

是否可以使用Android导航架构组件(Android Jetpack)有条件地设置startDestination?

我使用的导航Android的Jetpack的屏幕之间进行导航.现在我想动态设置startDestination.

我有一个名为MainActivity的Activity和两个Fragments,FragmentA和FragmentB.

var isAllSetUp : Boolean = // It is dynamic and I’m getting this from Preferences.

    If(isAllSetUp)
    {
     // show FragmentA
    }
    else
    {
     //show FragmentB
    }
Run Code Online (Sandbox Code Playgroud)

我想使用Navigation Architecture Component设置上面的流程.目前我使用startDestionation如下所示,但它不符合我的要求.

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/lrf_navigation"
   app:startDestination="@id/fragmentA">

   <fragment
       android:id="@+id/fragmentA"
       android:name="com.mindinventory.FragmentA"
       android:label="fragment_a"
       tools:layout="@layout/fragment_a" />
</navigation>
Run Code Online (Sandbox Code Playgroud)

是否可以使用Android导航架构组件有条件地设置startDestination?

android android-jetpack android-architecture-navigation

31
推荐指数
3
解决办法
9029
查看次数

如何以编程方式更改导航图的起始目标[Jetpack]

基本上,我有以下导航图:

在此输入图像描述

我希望fragment 2在到达之后将导航图中的起点更改为正确(为了防止fragment 1在按下后退按钮时返回 - 就像启动画面一样).

这是我的代码:

navGraph = navController.getGraph();
navGraph.setStartDestination(R.id.fragment2);
navController.setGraph(navGraph);
Run Code Online (Sandbox Code Playgroud)

但是,显然它不起作用,fragment 1按下后退按钮后又回来了.

我做错了吗?还有其他解决方案吗?

android android-navigation android-jetpack android-architecture-navigation

30
推荐指数
5
解决办法
1万
查看次数

Android Jetpack导航:如何在OnNavigatedListener中获取目标的片段实例?

我在android开发中使用Jetpack导航组件(一个活动,许多片段).

我想在OnNavigatedListener中获取目标的片段实例,如下所示.

可能吗?

class MainActivity : AppCompatActivity() {

    private lateinit var navController: NavController

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(this, R.layout.activity_main)
        navController = Navigation.findNavController(this, R.id.nav_host_fragment)
        navController.addOnNavigatedListener { controller, destination ->
            // Here
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

更新:场景

我想在每次导航的活动中获取片段的属性(或从方法返回的值).

例如,

val fragment = getFragmentInstanceFromDestination()
myActionBar.visible = fragment.getActionBarVisible()
Run Code Online (Sandbox Code Playgroud)

android android-jetpack android-architecture-navigation

11
推荐指数
1
解决办法
1930
查看次数

试图将我的LogCat输出到文件

我被告知这是一个命令行选项.但Eclipse的Run!Run Configurations ...!Target!附加仿真器命令行选项字段已被占用

-sdcard "C:\android-sdk-windows\tools\sd9m.img"
Run Code Online (Sandbox Code Playgroud)

如果我想写类似的东西

adb logcat -s MessageBox > "C:\Users\me\Documents\LogCatOutput.txt"
Run Code Online (Sandbox Code Playgroud)

然后我在哪里写它,以及如何(即语法是否正确)?我只需要输出一个过滤的标签,而不是详细的.("MessageBox"是我的TAG.再次,我不知道这个标点符号是否正确,或者甚至命令的位置.)

谢谢你的帮助.

android logcat

10
推荐指数
1
解决办法
2万
查看次数

如何使用 Jetpack Navigation 从嵌套 Fragment 导航到父 Fragment?

我有主导航:SplashFragment -> RegistrationFragment -> RootFragment

<fragment
    android:id="@+id/splashFragment"
    android:name="com.low6.low6.features.splash.SplashFragment"
    android:label="Splash"
    tools:layout="@layout/fragment_splash" >
    <action
        android:id="@+id/action_next"
        app:clearTask="true"
        app:destination="@id/registrationFragment" />
</fragment>

<fragment
    android:id="@+id/registrationFragment"
    android:name="com.low6.low6.features.registration.RegistrationFragment"
    android:label="Register">
    <action
        android:id="@+id/action_next"
        app:clearTask="true"
        app:destination="@id/rootFragment" />
</fragment>

<fragment
    android:id="@+id/rootFragment"
    android:name="com.low6.low6.core.RootFragment"
    android:label="@string/home"
    tools:layout="@layout/fragment_root" />
Run Code Online (Sandbox Code Playgroud)

我有嵌套的注册导航: RegistrationPersonalFragment -> RegistrationContactFragment -> RegistrationSecurityFragment

<fragment
    android:id="@+id/registrationPersonalFragment"
    android:name="com.low6.low6.features.registration.RegistrationPersonalFragment"
    android:label="Register">

    <action
        android:id="@+id/action_next"
        app:destination="@+id/registrationContactFragment" />
</fragment>

<fragment
    android:id="@+id/registrationContactFragment"
    android:name="com.low6.low6.features.registration.RegistrationContactFragment"
    android:label="Register">

    <action
        android:id="@+id/action_next"
        app:destination="@+id/registrationSecurityFragment" />
</fragment>

<fragment
    android:id="@+id/registrationSecurityFragment"
    android:name="com.low6.low6.features.registration.RegistrationSecurityFragment"
    android:label="Register">

    <action
        android:id="@+id/action_next"
        app:destination="@+id/rootFragment" />
</fragment>
Run Code Online (Sandbox Code Playgroud)

如何使用 Jetpack Navigation 组件从最后一个嵌套的 RegistrationSecurityFragment 重定向到 RootFragment?

目前

<action
    android:id="@+id/action_next"
    app:destination="@+id/rootFragment" />
Run Code Online (Sandbox Code Playgroud)

   navigateTo(R.id.action_next) …
Run Code Online (Sandbox Code Playgroud)

android android-navigation android-jetpack android-architecture-navigation

10
推荐指数
2
解决办法
9939
查看次数

在Windows下的C++项目中使用cpp-netlib

我想在我的Windows上运行的C++项目中使用cpp-netlib库.我严格遵循http://cpp-netlib.github.com/getting_started.html下的说明直到"获取CMake"部分,这是我停止理解指令的地方.CMake确实是非强制性的吗?如果是这样,所需的确切步骤是什么,以便我可以在我的项目中使用该库?

如果有人可以在这里向我提供说明,或者请参考详细指南,那就太棒了.谷歌并没有那么帮助我.

c++ cpp-netlib

9
推荐指数
1
解决办法
4458
查看次数

Jetpack导航:NavHostManager不是FragmentManager的活动片段

我正在使用Jetpack Navigation来处理Fragments的导航.
我一直在关注文档并安装了所需的组件,当尝试显示托管NavHost片段的活动时,应用程序仍然崩溃

例外:

java.lang.IllegalArgumentException: Fragment NavHostFragment{820022f} is not an active fragment of FragmentManager FragmentManager{5a5703c in HostCallbacks{a0b41c5}}
        at android.support.v4.app.FragmentManagerImpl.setPrimaryNavigationFragment(FragmentManager.java:3389)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:783)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2595)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2382)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2337)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2244)
Run Code Online (Sandbox Code Playgroud)

主要活动布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LoginActivity" >

    <fragment
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/my_nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        app:navGraph="@navigation/nav_graph"
        app:defaultNavHost="true"
        />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

主要活动 - Kotlin

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.login_activity)
        if (savedInstanceState == null) {
            supportFragmentManager.beginTransaction()
                    .replace(R.id.container, LoginFragment.newInstance())
                    .commitNow()
        }
    }

    override fun onSupportNavigateUp()
        = findNavController(R.id.my_nav_host_fragment).navigateUp()

} …
Run Code Online (Sandbox Code Playgroud)

android android-navigation kotlin-android-extensions android-jetpack android-architecture-navigation

9
推荐指数
1
解决办法
2793
查看次数

Android Jetpack导航库和onActivityResult

我正在尝试将应用迁移到GoogleIO'18宣布的新导航架构组件

假设我需要使用通常以开始的活动startActivityForResult。该活动来自库活动或系统活动,因此我无法对其进行修改。

有什么方法可以将此活动作为目的地包含在导航图中并从中获取结果?

android android-activity android-jetpack android-architecture-navigation

9
推荐指数
1
解决办法
1799
查看次数

Jetpack 导航到一个共同的目的地

我一直在 Jetpack 中使用新的新 Navigation-API,但遇到了一个找不到令人满意的解决方案的问题。

基本上我正在创建的应用程序有大量不同的片段。大多数片段与后端对话,当他们这样做时,他们会发现他们的会话已超时。发生这种情况时,我想转到登录片段。我能够做到这一点的唯一方法是为每个片段创建一个动作,目标指向登录屏幕。这是很多我宁愿避免的样板。有没有更简单的方法来做到这一点?

navigation android android-jetpack android-architecture-navigation

9
推荐指数
1
解决办法
4103
查看次数