我的布局中有两个FloatingActionButton。两者都以相同的方式附加到CoordinatorLayout。
void StartAlarm(int day, int hour, int minutes) {
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minutes);
calendar.set(Calendar.SECOND, 0);
Random r = new Random();
int rcode = r.nextInt(10000 - 50) + 50;
rcodeAlarm.add(String.valueOf(rcode));
Intent myIntent = new Intent(Time.this, MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(Time.this, rcode, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
timeAlarm.add(String.valueOf(calendar.getTimeInMillis()));
}
然而,当我展示一个小吃店时,只有底部的FAB上下移动。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawerLayout"
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"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
[ appbar, toolbar, content... ]
<android.support.design.widget.FloatingActionButton
android:id="@+id/anon_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="88dp"
android:layout_marginRight="@dimen/fab_margin"
android:clickable="true"
android:onClick="onFabClick"
android:src="@drawable/ic_cloud_upload_white_24dp"
android:tint="?colorAccent"
app:backgroundTint="@color/tint_inverted_fab"
app:borderWidth="0dp"
app:layout_anchor="@id/coordinatorLayout"
app:layout_anchorGravity="bottom|end"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/keyboard_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
android:onClick="onFabClick"
android:src="@drawable/ic_keyboard_white_24dp"
app:borderWidth="0dp"
app:layout_anchor="@id/coordinatorLayout"
app:layout_anchorGravity="bottom|end"
/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
如何使两者都移动?
答案 0 :(得分:4)
我找到的解决方案是再次实现FloatingActionButton行为并在FAB中明确设置它。
关于如何实现默认行为,BaseLab的人员有一篇好文章here,其匹配的GitHub repo。
创建自己的此类行为重新实现后,只需将其设置在布局文件中,如下所示:
Snackbar.make(mCoordinator, "FAB pressed", Snackbar.LENGTH_LONG).show();
现在两个按钮将在你的SnackBar出现时移动!