我想要对话框下面有模糊的屏幕,所以我拍摄了 Activity 的“屏幕截图”,对其进行模糊处理并将其设置为对话框窗口的背景,如 BitmapDrawable。奇怪的是,对话框不再以屏幕为中心,即使调用了 setCanceledOnTouchOutside(true),触摸外部对话框也不会关闭它。
问题是:为什么这不起作用?分别如何创建背景模糊的对话框?
public class BlurDialog extends DialogFragment {
public BlurDialog() {
}
public static BlurDialog newInstance() {
return new BlurDialog();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
.setTitle("Title")
.setMessage("Message")
.setPositiveButton("OK", null)
.setNegativeButton("Cancel", null)
.create();
alertDialog.setCanceledOnTouchOutside(true);
View view = getActivity().getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
Bitmap b1 = view.getDrawingCache();
Rect frame = new Rect();
getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
final int width = getActivity().getWindow().getDecorView().getWidth();
final int height = getActivity().getWindow().getDecorView().getHeight();
Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height-statusBarHeight);
//define this only once if blurring multiple times
RenderScript rs = RenderScript.create(getActivity());
//this will blur the bitmapOriginal with a radius of 8 and save it in bitmapOriginal
final Allocation input = Allocation.createFromBitmap(rs, b); //use this constructor for best performance, because it uses USAGE_SHARED mode which reuses memory
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(8f);
script.setInput(input);
script.forEach(output);
output.copyTo(b);
alertDialog.getWindow().setBackgroundDrawable(new BitmapDrawable(getResources(), b));
return alertDialog;
}
}
最佳答案
这篇文章很旧,但供您引用:
要创建背景模糊的对话框,你可以使用这个库:
https://github.com/tvbarthel/BlurDialogFragment
您可以创建一个扩展 BlurDialogFragment 的类,并在 onCreateView 方法中扩展您的自定义布局。请参见下面的示例:
public class CustomDialogFragment extends BlurDialogFragment {
@Override
protected boolean isActionBarBlurred() {
// Enable or disable the blur effect on the action bar.
// Disabled by default.
return true;
}
@Override
protected int getBlurRadius() {
// Allow to customize the blur radius factor.
return 7;
}
@Override
protected boolean isDimmingEnable() {
// Enable or disable the dimming effect.
// Disabled by default.
return false;
}
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_fragment_layout, container,
false);
return v;
}
从您的 Activity 中显示对话框:
FragmentManager fragmentManager = getFragmentManager();
CustomDialogFragment cdf = new CustomDialogFragment();
cdf.show(fragmentManager,"yourTag");
`
关于android - 对话框背后的模糊背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25642472/
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我有一张背景图片,我想在其中添加一个文本框。我想弄清楚如何将标题放置在其顶部的正确位置。(我使用标题是因为我需要自动换行功能)。现在,我只能让文本显示在左上角,但我需要能够手动定位它的开始位置。require'RMagick'require'Pry'includeMagicktext="Loremipsumdolorsitamet"img=ImageList.new('template001.jpg')img 最佳答案 这是使用convert的ImageMagick命令行的答案。如果你想在Rmagick中使用这个方法,你必须自己移植
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我最近与一位同事讨论了以下Ruby语法:value=ifa==0"foo"elsifa>42"bar"else"fizz"end我个人并没有看到太多这种逻辑,但我的同事指出,这实际上是一种相当普遍的Rubyism。我试着用谷歌搜索这个主题,但没有找到任何文章、页面或SO问题来讨论它,这让我相信这可能是一种非常实际的技术。然而,另一位同事发现语法令人困惑,而是将上面的逻辑写成这样:ifa==0value="foo"elsifa>42value="bar"elsevalue="fizz"end缺点是value=的重复声明和隐式elsenil的丢失,如果我们想使用它的话。这也感觉它与Ruby
在尝试构建Rubygem(使用Bundler)时,我倾向于使用Bundler提供的REPL测试代码——可通过bundleconsole访问。有什么方法可以重新加载整个项目吗?我最终再次加载单个(更改的)文件以测试新更改。 最佳答案 以下hack适用于我的一个相对简单的gem和Ruby2.2.2。我很想看看它是否适合你。它做出以下假设:您具有传统的文件夹结构:一个名为lib/my_gem_name.rb的文件和一个文件夹lib/my_gem_name/,其中包含任何文件/文件夹结构。您要重新加载的所有类都嵌套在您的顶级模块MyGemN
我有一个Rails应用程序,现在设置了ElasticSearch和Tiregem以在模型上进行搜索,我想知道我应该如何设置我的应用程序以对模型中的某些索引进行模糊字符串匹配。我将我的模型设置为索引标题、描述等内容,但我想对其中一些进行模糊字符串匹配,但我不确定在何处进行此操作。如果您想发表评论,我将在下面包含我的代码!谢谢!在Controller中:defsearch@resource=Resource.search(params[:q],:page=>(params[:page]||1),:per_page=>15,load:true)end在模型中:classResource'Us
我无法遍历整个unicode字符范围。我到处找...我正在构建一个模糊器,并希望将所有unicode字符(一次一个)嵌入到一个url中。例如:http://www.example.com?a=\uff1c我知道有一些内置工具,但我需要更多的灵active。如果我能像下面那样做:"\u"+"ff1c"那就太好了。这是我得到的最接近的:char="\u0000"...#withiniterationchar.succ!...但在字符"\u0039"之后,即数字9,我将得到"10"而不是":" 最佳答案 您可以使用pack将数字转换为UT
这个问题在这里已经有了答案:Nokogiri:SelectcontentbetweenelementAandB(3个答案)关闭2年前。我正在从url中抓取文本的div,并想删除具有backtotop类的段落下方的所有内容。我在stackoverflow上看到了一段遍历代码片段,看起来很有希望,但我不知道如何将它合并,所以@el只包含第一个p.backtotop之前的所有内容分区我的代码:@doc=Nokogiri::HTML(open(url))@el=@doc.css("div")[0]end遍历片段:doc=Nokogiri::HTML(code)stop_node=doc.css
我在View中有这段代码prawn_document(:page_size=>"A4",:top_margin=>80,:bottom_margin=>40,:background=>"public/uploads/1.png")do|pdf|creation_date=Time.now.strftime('%d-%m-%Y')posts=@posts.eachdo|post|pdf.pad(10)dopdf.textpost.titlepdf.textpost.textendendpdf.page_count.timesdo|i|pdf.go_to_page(i+1)pdf.draw
今天我遇到了下面的正则表达式,想知道Ruby会用它做什么:>"#a"=~/^[\W].*+$/=>0>"1a"=~/^[\W].*+$/=>nil在这种情况下,Ruby似乎忽略了+字符。如果这是不正确的,我不确定它在做什么。我猜它没有被解释为量词,因为*没有转义并且被用作量词。在Perl/Ruby正则表达式中,有时当一个字符(例如,-)在不能被解释为特殊字符的上下文中使用时,它会被视为文字。但如果在这种情况下发生这种情况,我希望第一个匹配失败,因为左值字符串中没有+。这是对+字符的巧妙正确使用吗?以上行为是错误吗?我是否遗漏了一些明显的东西? 最佳答案