点击 FAB 上的 Alpha 背景
Alpha background on FAB clicked
我正在使用库 https://github.com/futuresimple/android-floating-action-button 来创建效果很好的 fab 按钮。我尝试了几个库,但 none 使用大多数应用程序中使用的效果与 fab(或 Google 应用程序,如 keep,收件箱),当单击 fab 时,整个应用程序的背景变成半透明的白色或黑色,这取决于。我找不到任何方法来做到这一点。是否有可能有一个例子或类似的东西来做这种效果?你可以在这张图片中看到我的意思:
半黑背景
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/semi_white_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white_semi_transparent"
android:visibility="gone" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/listFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/content_frame"
android:visibility="gone" >
<TextView
android:id="@+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cabinet_color"
android:fontFamily="sans-serif"
android:gravity="center_vertical"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:textColor="#fff"
android:textSize="17sp"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/status"
android:clipToPadding="false"
android:scrollbars="vertical" />
<LinearLayout
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<ImageView
android:id="@+id/emptyImage"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp"
android:scaleType="fitXY"
android:src="?empty_image" />
<TextView
android:id="@+id/emptyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:lineSpacingMultiplier="1.4"
android:paddingBottom="16dp"
android:text="@string/no_files"
android:textColor="?empty_text"
android:textSize="22sp" />
</LinearLayout>
</RelativeLayout>
<ProgressBar
android:id="@android:id/progress"
style="?android:progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminateOnly="true" />
</RelativeLayout>
这是我的 layout.xml,但似乎根本无法正常工作,因为我 want.Seems 没有与整个视图重叠,只是根据需要着色..
喜欢你的问题...
这个库不允许你设置添加按钮点击事件,你可能需要自己更改库代码,使用这个想法:
使用 Relatie 或 framelayout 并在 FAB 后面添加黑色背景或图像。
现在在库中 class FloatingActionsMenu.class 找到并评论这段代码:
//mAddButton.setOnClickListener(new OnClickListener()
//{
// @Override
// public void onClick(View v)
// {
// toggle();
// }
//});
然后在class,
里面加上这个方法
public void setAddButtonClickListener(OnClickListener listener)
{
mAddButton.setOnClickListener(listener);
}
在您的 activity 中定义点击侦听器,例如
OnClickListener listener = new OnClickListener()
{
@Override
public void onClick(View v)
{
if (floatingActionMenuButton.isExpanded())
{//make the background visible
}
else
{//make the background invisible
}
floatingActionMenuButton.toggle();
}
};
并将其传递给 FAB
floatingActionMenuButton.setAddButtonClickListener(listener);
构建库和项目,希望这会有所帮助!
我发现这是我认为最简单的解决方案,而且效果很好:
fam.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
@Override
public void onMenuExpanded() {
dimmedBackground.setVisibility(View.VISIBLE);
}
@Override
public void onMenuCollapsed() {
dimmedBackground.setVisibility(View.GONE);
}
});
您需要将 activity 包装在 FrameLayout 中。 FrameLayout 应该有 2 个孩子
- 您的 activity 内容
- 另一个包含 FloatingActionsMenu 的框架布局
这是相关的代码片段。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="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="in.city.bytes.view.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- other content in the activity -->
</LinearLayout>
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white_overlay">
<!-- floating action menu with buttons -->
</FrameLayout>
在您的 activity 中,更改单击 FAB 菜单时 frame_layout
的 alpha。我还写了一篇博客来解释它。 http://www.rishabhsinghal.in/implement-floating-action-button-similar-to-inbox-by-gmail-or-evernote/
floatingActionMenu.setOnMenuToggleListener(
new FloatingActionMenu.OnMenuToggleListener() {
@Override
public void onMenuToggle(boolean opened) {
if(opened){
//show backgroud
}else{
//hide backgroud
}
}
});
我正在使用库 https://github.com/futuresimple/android-floating-action-button 来创建效果很好的 fab 按钮。我尝试了几个库,但 none 使用大多数应用程序中使用的效果与 fab(或 Google 应用程序,如 keep,收件箱),当单击 fab 时,整个应用程序的背景变成半透明的白色或黑色,这取决于。我找不到任何方法来做到这一点。是否有可能有一个例子或类似的东西来做这种效果?你可以在这张图片中看到我的意思:
半黑背景
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/semi_white_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white_semi_transparent"
android:visibility="gone" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/listFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/content_frame"
android:visibility="gone" >
<TextView
android:id="@+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cabinet_color"
android:fontFamily="sans-serif"
android:gravity="center_vertical"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:textColor="#fff"
android:textSize="17sp"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/status"
android:clipToPadding="false"
android:scrollbars="vertical" />
<LinearLayout
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<ImageView
android:id="@+id/emptyImage"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp"
android:scaleType="fitXY"
android:src="?empty_image" />
<TextView
android:id="@+id/emptyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:lineSpacingMultiplier="1.4"
android:paddingBottom="16dp"
android:text="@string/no_files"
android:textColor="?empty_text"
android:textSize="22sp" />
</LinearLayout>
</RelativeLayout>
<ProgressBar
android:id="@android:id/progress"
style="?android:progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminateOnly="true" />
</RelativeLayout>
这是我的 layout.xml,但似乎根本无法正常工作,因为我 want.Seems 没有与整个视图重叠,只是根据需要着色..
喜欢你的问题...
这个库不允许你设置添加按钮点击事件,你可能需要自己更改库代码,使用这个想法: 使用 Relatie 或 framelayout 并在 FAB 后面添加黑色背景或图像。
现在在库中 class FloatingActionsMenu.class 找到并评论这段代码:
//mAddButton.setOnClickListener(new OnClickListener()
//{
// @Override
// public void onClick(View v)
// {
// toggle();
// }
//});
然后在class,
里面加上这个方法public void setAddButtonClickListener(OnClickListener listener)
{
mAddButton.setOnClickListener(listener);
}
在您的 activity 中定义点击侦听器,例如
OnClickListener listener = new OnClickListener()
{
@Override
public void onClick(View v)
{
if (floatingActionMenuButton.isExpanded())
{//make the background visible
}
else
{//make the background invisible
}
floatingActionMenuButton.toggle();
}
};
并将其传递给 FAB
floatingActionMenuButton.setAddButtonClickListener(listener);
构建库和项目,希望这会有所帮助!
我发现这是我认为最简单的解决方案,而且效果很好:
fam.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
@Override
public void onMenuExpanded() {
dimmedBackground.setVisibility(View.VISIBLE);
}
@Override
public void onMenuCollapsed() {
dimmedBackground.setVisibility(View.GONE);
}
});
您需要将 activity 包装在 FrameLayout 中。 FrameLayout 应该有 2 个孩子
- 您的 activity 内容
- 另一个包含 FloatingActionsMenu 的框架布局
这是相关的代码片段。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="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="in.city.bytes.view.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- other content in the activity -->
</LinearLayout>
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white_overlay">
<!-- floating action menu with buttons -->
</FrameLayout>
在您的 activity 中,更改单击 FAB 菜单时 frame_layout
的 alpha。我还写了一篇博客来解释它。 http://www.rishabhsinghal.in/implement-floating-action-button-similar-to-inbox-by-gmail-or-evernote/
floatingActionMenu.setOnMenuToggleListener(
new FloatingActionMenu.OnMenuToggleListener() {
@Override
public void onMenuToggle(boolean opened) {
if(opened){
//show backgroud
}else{
//hide backgroud
}
}
});