晶圆厂在协调器布局中不会隐藏

时间:2018-07-06 15:48:24

标签: android android-coordinatorlayout floating-action-button

我在布局xml中有以下代码。我想让fab在用户单击后消失,并在sendData()中指定的操作后再次出现

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="org.toto.test.RecordAction">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="37dp"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#40f4b8"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_record_action" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_marginTop="35dp"
        android:layout_width="match_parent"
        android:layout_height="567dp"
        app:srcCompat="@drawable/sahasrakshi"
        tools:layout_editor_absoluteY="0dp" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:backgroundTint="@color/colorPrimary"
        app:srcCompat="@drawable/ic_send_white_18dp" />

</android.support.design.widget.CoordinatorLayout>

并尝试更改晶圆厂的可见性。它不起作用。调用的代码是

CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setAnchorId(View.NO_ID);
fab.setLayoutParams(p);

fab = (FloatingActionButton) findViewById(R.id.fab);


fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (checkValidation())

            //fab.setBackgroundColor(Color.parseColor("#ffffff"));
            //fab.hide();
            fab.setVisibility(View.INVISIBLE);

            sendData();

            //fab.setBackgroundColor(Color.parseColor("#e7ffcc"));
            //fab.show();
            //fab.setEnabled(true);
            fab.setVisibility(View.VISIBLE);
    }
});

试图更改颜色,使用了show()和hide(),但无法这样做。有人可以指导我吗?

Adding sendData()

protected void sendData() {

    amtInWords = convertNumberToWords(Amount);
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS)
            != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.SEND_SMS)) {
        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.SEND_SMS},
                    MY_PERMISSIONS_REQUEST_SEND_SMS);
        }
    } else {
        sendSMS();
    }
    getDeviceName();

    editInvisibleFocusHolder.setInputType(InputType.TYPE_NULL);
    editInvisibleFocusHolder.requestFocus();

        captureScreen();
        sendEmail();
        onFabVisible(true);
        quit();
    }
}

1 个答案:

答案 0 :(得分:0)

使用自定义方法

public void onFabVisible(boolean visible) {
    if (fab!= null) {
        fab.setVisibility(visible ? View.VISIBLE : View.GONE);
        fab.setAlpha(visible ? 1f : 0f);
        fab.setScaleY(visible ? 1f : 0f);
        fab.setScaleX(visible ? 1f : 0f);
    }
}

如果sendData()是异步请求,则在回调中使用onFabVisible(true)

更新

您需要创建一个在完成所有这些方法之后将要调用的方法。将检查是否已发送所有内容。

示例:

boolean smsSent = false;
boolean emailSant = false;
private void chackAllSent() {
    if (havePermission && smsSent && emailSant) {
        onFabVisible(true);
    }
}

发送每个信息后调用此方法。 然后更改OnClickListener

fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (checkValidation())
            onFabVisible(false);
            sendData();
    }
});

并在sendData()方法中删除onFabVisible(true)