在点击相机按钮之前,它看起来像: 单击相机按钮并选择图像后,相机按钮变为隐形或图库按钮隐藏它 我的布局xml文件:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/item_recycler_images" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_camera" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_invisible"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="top|end"
android:layout_margin="15dp"
android:visibility="invisible"
app:layout_anchor="@id/camera"
app:layout_anchorGravity="top" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
app:layout_anchor="@id/fab_invisible"
app:layout_anchorGravity="top"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_gallery" />
</android.support.design.widget.CoordinatorLayout>
我使用过支持版:'27 .0.0'。 在三星Galaxy S3(Android版本5.0.1)上观察到此错误。 在三星galaxy Tab S上没有观察到这个bug。 我处理点击事件的代码
public class ScanDocumentActivity extends AppCompatActivity implements Adapter.OnCloseClickListener {
private static final int REQUEST_CAMERA_PERMISSION = 111;
private static final int REQUEST_IMAGE_CAMERA = 99;
public static final int SCAN_REQUEST = 330;
@BindView(R.id.recyclerView)
RecyclerView recyclerView;
@BindView(R.id.gallery)
FloatingActionButton gallery;
@BindView(R.id.camera)
FloatingActionButton camera;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.coordinator)
CoordinatorLayout coordinatorLayout;
Adapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan_document);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
toolbar.setTitle("Salom");
adapter = new Adapter(this);
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
recyclerView.setAdapter(adapter);
gallery.setOnClickListener(view -> galleryIntent());
gallery.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(this, R.color.colorPrimary)));
camera.setOnClickListener(view -> cameraIntent());
}
public void cameraIntent() {
Intent intent = new Intent(this, ScanActivity.class);
intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, ScanConstants.OPEN_CAMERA);
startActivityForResult(intent, REQUEST_IMAGE_CAMERA);
}
public void galleryIntent() {
Intent intent = new Intent(this, ScanActivity.class);
intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, ScanConstants.OPEN_MEDIA);
startActivityForResult(intent, REQUEST_IMAGE_CAMERA);
}