【问题标题】:Hide/show FAB on uithread在uithread上隐藏/显示FAB
【发布时间】:2017-06-11 14:53:19
【问题描述】:

我在这里尝试的是在结果返回空值/字符串时隐藏 FAB 和文本。方法 hideTextView() 和 setText() 工作正常,但无论是否返回空字符串,FAB 仍然始终显示。

   if (args.getString("results").isEmpty()) {
        activity.hideTextView(text);
        activity.hideButton(fabButton);
    } else {
        activity.setText(text, args.getString("text"));
        activity.showButton(fabButton);

以下是我用于显示/隐藏 TextView 和 FAB 的方法。我也试过floatingActionButton.hide()floatingActionButton.show() 但还是不行

 public void hideButton(final FloatingActionButton floatingActionButton) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                floatingActionButton.setVisibility(View.GONE);
                //floatingActionButton.hide()
            }
        });
    }

    public void showButton(final FloatingActionButton floatingActionButton) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                floatingActionButton.setVisibility(View.VISIBLE);
                //floatingActionButton.show();
            }
        });
    }

 public void hideTextView(final TextView textView) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                textView.setVisibility(View.GONE);
            }
        });
    }

public void setText(final TextView text, final String value) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                text.setText(value);
            }
        });
    }

工厂

<android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/fabButton"
        android:layout_alignParentEnd="true"
        android:layout_below="@+id/cover"
        android:src="@drawable/ic_icon1"
        app:backgroundTint="@color/colorAccent"
        android:clickable="true"
        android:layout_marginRight="210dp"
        android:layout_marginTop="-28dp"
        android:adjustViewBounds="false"/>

【问题讨论】:

  • 您使用的是哪个 fab 内置的 android 或其他一些库?
  • @SohailZahid 内置晶圆厂
  • @BXUMZSE 从哪里activity.hideButton(fabButton); 正在调用后台线程?

标签: android floating-action-button


【解决方案1】:

这可能是由于您的 xml 代码中的 app:layout_anchor 属性。必须在更改可见性之前更改锚点。尝试在 run 中添加这段代码:

CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) floatingActionButton.getLayoutParams();
p.setAnchorId(View.NO_ID);
floatingActionButton.setLayoutParams(p);
floatingActionButton.setVisibility(View.GONE);

【讨论】:

    【解决方案2】:

    使用floatingActionButton.hide(); 代替floatingActionButton.setVisibility(View.GONE);

    floatingActionButton.hide(); // to hide
    floatingActionButton.show();// to show
    

    【讨论】:

      猜你喜欢
      • 2017-09-12
      • 2016-02-18
      • 2017-01-12
      • 2017-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多