小编mon*_*key的帖子

在 ListView 中的键盘上方滚动 TextFormField

我的应用程序中有以下抽屉:

在此处输入图片说明

当我按下密码时,TextFormField我得到以下信息:

在此处输入图片说明

如您所见,密码TextFormField已被覆盖。我试图解决这个问题,正如这里所建议的:

class _LoginDrawer extends State<LoginDrawer> {
  static var _listViewScrollController = new ScrollController();

  @override
  Widget build(BuildContext context) => new Drawer(
    child: new ListView(
      controller: _listViewScrollController,
      children: <Widget>[
        // ...
        new Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: new GestureDetector(
            onTap: () {
              SchedulerBinding.instance.addPostFrameCallback((_) {
                _listViewScrollController.jumpTo(
                 _listViewScrollController.position.maxScrollExtent);
              });
            },
            child: new TextFormField(
                obscureText: true,
                decoration: new InputDecoration(labelText: "Password")),
          ),
        ),
      ],
    ),
  );
}
Run Code Online (Sandbox Code Playgroud)

但这并不能解决问题,该应用程序的行为与以前相同。还有一些人建议使用 a ListViewthat is reversed 然后使用,listViewController.jumpTo(0.0)但这导致了不需要的效果,所有小部件都从底部开始:

在此处输入图片说明

flutter

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

使用 Android 导航架构组件在导航图之间进行简单导航

这是一个简单的导航设置示例,经过一段时间的研究,我无法使用导航组件库。

假设我有以下屏幕: 在此处输入图片说明

顶部的粘性片段和底部的片段在它们自己的导航图中,这里是 main_activity.xml:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/nav_sticky_top"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/navigation_graph_sticky_top" />

    <fragment
        android:id="@+id/navigation_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/nav_sticky_top"
        app:navGraph="@navigation/navigation_graph" />

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

当我按“导航到同级片段”时,它导航到底部导航图中的同级片段,这是正确的,结果:

在此处输入图片说明

这是 navigation_graph.xml:

<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/navigation_graph.xml"
    app:startDestination="@id/blankFragment1">

    <fragment
        android:id="@+id/blankFragment1"
        android:name="com.example.myapplication.BlankFragment1"
        android:label="fragment_blank_fragment1"
        tools:layout="@layout/fragment_blank_fragment1">

        <action
            android:id="@+id/action_blankFragment1_to_siblingFragment"
            app:destination="@id/siblingFragment" />

    </fragment>

    <fragment
        android:id="@+id/siblingFragment"
        android:name="com.example.myapplication.SiblingFragment"
        tools:layout="@layout/fragment_sibling_fragment" />

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

现在我想实现“导航到全屏片段”按钮,该按钮应该导航到一个位于单独的第三导航图中的全屏片段,并且应该位于粘性片段导航图上方和下方的导航图。如何正确实现这一目标?我的意思是没有像将顶部导航图片段的可见性设置为 GONE 以及在底部导航图中导航到全屏片段这样的技巧。

android android-architecture-components android-architecture-navigation

6
推荐指数
1
解决办法
3050
查看次数

在 API 21 和 22 中强制使用 AnimatedVectorDrawableCompat 以使用 registerAnimationCallback

我正在为支持 Android API 19-26 的应用程序使用可绘制动画矢量。为了重新启动动画(它是一个自定义循环加载动画),我使用 AnimatedVectorDrawable.registerAnimationCallback,在 onAnimationEnd 回调中重新启动动画。这适用于 API >= 23 并且由于 AnimatedVectorDrawableCompat 它也适用于 API 19。

但是,它不适用于 API 21 和 22,因为类 AnimatedVectorDrawable 已经存在于这些 API 中,但 registerAnimationCallback 方法仅在 API 23 中添加。如何强制运行 API 21 或 22 的设备改用 AnimatedVectorDrawableCompat他们的 AnimatedVectorDrawable 类,以便我可以使用 registerAnimationCallback?

这是我编写的用于为不同 API 版本启动动画的方法(在 Kotlin 中):

private fun startAnimation() {
  if (Build.VERSION.SDK_INT >= 23) {
    ((circular_progress.drawable as LayerDrawable)
        .findDrawableByLayerId(R.id.loading_circle) as AnimatedVectorDrawable).apply {
      registerAnimationCallback(@TargetApi(23)
      object : Animatable2.AnimationCallback() {
        override fun onAnimationEnd(drawable: Drawable?) {
          super.onAnimationEnd(drawable)
          this@apply.start()
        }

        override fun onAnimationStart(drawable: Drawable?) = super.onAnimationStart(drawable)
      }) …
Run Code Online (Sandbox Code Playgroud)

api animation android

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

在 Espresso 测试期间发送模拟器控制台命令

谷歌解释了如何控制 Android 模拟器的许多参数,例如电池的当前电量、传感器输入等:https : //developer.android.com/studio/run/emulator-console.html

我想创建一个 Espresso 测试,在测试期间更改模拟器的这些参数,这可能吗?我知道有以下方法:

InstrumentationRegistry.getInstrumentation().uiAutomation
    .executeShellCommand("someShellCommand")
Run Code Online (Sandbox Code Playgroud)

可以在测试期间调用此方法,但要更改仿真器的系统参数,我首先必须通过登录telnet localhost 5554,然后才能操作仿真器参数,例如:power capacity 30,将电池电量更改为 30% . 我如何在 Espresso 测试期间做到这一点?

android android-emulator android-espresso

3
推荐指数
1
解决办法
883
查看次数