浮动操作按钮和白色背景
Floating action button and white background
事实上,我正在寻找一种模仿 FAB 收件箱的方法。当用户按下红色按钮时,应该会出现一个 opac 视图和一个菜单。因为图片更有意义,见下图
我知道它存在这个很棒的库 (https://github.com/futuresimple/android-floating-action-button),有了这个库,我可以显示浮动操作菜单。但我的问题是显示白色背景(不透明)。我没有找到解决我的问题的方法...
提前致谢
将 FloatingActionMenu
放在 FrameLayout
内,它将位于其他视图之上,并且在宽度和高度上与父视图匹配。使用相同的边距相应地从菜单右侧提升和偏移。
将 OnFloatingActionsMenuUpdateListener
设置为您的浮动操作菜单。现在 toggle/replace 框架布局背景颜色内部方法:
@Override
void onMenuExpanded(){
mFrameLayoutWrapper.setBackgroundColor(mAlpaWhite);
}
@Override
void onMenuCollapsed(){
mFrameLayoutWrapper.setBackgroundColor(Color.TRANSPARENT);
}
我是通过下面的方法达到你说的效果的。我只是在浮动按钮后面和其他布局上方添加了一个视图,并保持视图可见性 GONE,直到菜单展开。然后我将视图可见性设置为 VISIBLE。是的,我将视图的背景设置为您想要的任何不透明颜色。
我的代码
我的XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Other View here"
android:textSize="50dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:id="@+id/background_dimmer"
android:visibility="gone"
android:background="#55000000"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/multiple_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
fab:fab_addButtonColorNormal="@color/white"
fab:fab_addButtonColorPressed="@color/white_pressed"
fab:fab_addButtonPlusIconColor="@color/half_black"
fab:fab_labelStyle="@style/menu_labels_style"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/action_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/white"
fab:fab_title="Action A"
fab:fab_colorPressed="@color/white_pressed"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
并且在处理 FloatingButton 的 Activity 或 Fragment 处
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
setFloatingButtonControls();
}
private void setFloatingButtonControls(){
this.bckgroundDimmer = findViewById(R.id.background_dimmer);
this.floatingActionsMenu = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
this.floatingActionsMenu.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
@Override
public void onMenuExpanded() {
bckgroundDimmer.setVisibility(View.VISIBLE);
}
@Override
public void onMenuCollapsed() {
bckgroundDimmer.setVisibility(View.GONE);
}
});
}
这将产生您想要的效果。希望这可以帮助。它确实帮助了我。 :)
使用工具栏、浮动菜单、您的内容和相关布局进行协调布局。将相对布局的背景颜色设置为白色透明并将其可见性设置为消失。在 activity 中设置 "NoActionBar" 主题并使用工具栏而不是操作栏。现在,每当您打开浮动菜单时,将相对布局的可见性设置为可见,并在关闭时设置回消失。
当我向右添加浮动时,它确实使我的组件移动到我想要的位置,但也有一个白色背景,这不是必需的,但我可以通过在父级中引入“溢出:隐藏”来解决它 div。那应该可以解决问题
事实上,我正在寻找一种模仿 FAB 收件箱的方法。当用户按下红色按钮时,应该会出现一个 opac 视图和一个菜单。因为图片更有意义,见下图
我知道它存在这个很棒的库 (https://github.com/futuresimple/android-floating-action-button),有了这个库,我可以显示浮动操作菜单。但我的问题是显示白色背景(不透明)。我没有找到解决我的问题的方法...
提前致谢
将 FloatingActionMenu
放在 FrameLayout
内,它将位于其他视图之上,并且在宽度和高度上与父视图匹配。使用相同的边距相应地从菜单右侧提升和偏移。
将 OnFloatingActionsMenuUpdateListener
设置为您的浮动操作菜单。现在 toggle/replace 框架布局背景颜色内部方法:
@Override
void onMenuExpanded(){
mFrameLayoutWrapper.setBackgroundColor(mAlpaWhite);
}
@Override
void onMenuCollapsed(){
mFrameLayoutWrapper.setBackgroundColor(Color.TRANSPARENT);
}
我是通过下面的方法达到你说的效果的。我只是在浮动按钮后面和其他布局上方添加了一个视图,并保持视图可见性 GONE,直到菜单展开。然后我将视图可见性设置为 VISIBLE。是的,我将视图的背景设置为您想要的任何不透明颜色。
我的代码
我的XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Other View here"
android:textSize="50dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:id="@+id/background_dimmer"
android:visibility="gone"
android:background="#55000000"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/multiple_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
fab:fab_addButtonColorNormal="@color/white"
fab:fab_addButtonColorPressed="@color/white_pressed"
fab:fab_addButtonPlusIconColor="@color/half_black"
fab:fab_labelStyle="@style/menu_labels_style"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/action_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/white"
fab:fab_title="Action A"
fab:fab_colorPressed="@color/white_pressed"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
并且在处理 FloatingButton 的 Activity 或 Fragment 处
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
setFloatingButtonControls();
}
private void setFloatingButtonControls(){
this.bckgroundDimmer = findViewById(R.id.background_dimmer);
this.floatingActionsMenu = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
this.floatingActionsMenu.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
@Override
public void onMenuExpanded() {
bckgroundDimmer.setVisibility(View.VISIBLE);
}
@Override
public void onMenuCollapsed() {
bckgroundDimmer.setVisibility(View.GONE);
}
});
}
这将产生您想要的效果。希望这可以帮助。它确实帮助了我。 :)
使用工具栏、浮动菜单、您的内容和相关布局进行协调布局。将相对布局的背景颜色设置为白色透明并将其可见性设置为消失。在 activity 中设置 "NoActionBar" 主题并使用工具栏而不是操作栏。现在,每当您打开浮动菜单时,将相对布局的可见性设置为可见,并在关闭时设置回消失。
当我向右添加浮动时,它确实使我的组件移动到我想要的位置,但也有一个白色背景,这不是必需的,但我可以通过在父级中引入“溢出:隐藏”来解决它 div。那应该可以解决问题