本文介绍了要设置自定义布局的背景与ImageView的为透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是Android开发者文档建立一个自定义对话框,为了这个,我做了一个布局文件
I am building a Custom dialog box using the Android Developer docs link , for this i made a layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rotatelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#80000000"
>
<ImageView
android:id="@+id/dialogimage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
,我是充气该对话框中,
and i am inflating this dialog,
AlertDialog dialog;
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(TabsActivity.this);
LayoutInflater inflator = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.rotate_dialog_layout, (ViewGroup) findViewById(R.id.rotatelayout));
ImageView image = (ImageView) view.findViewById(R.id.dialogimage);
image.setOnClickListener(new RotateLockListener());
image.setBackgroundColor(Color.parseColor("#80000000"));
if(locked)
{
image.setImageResource(R.drawable.lock_icon);
}
else
{
image.setImageResource(R.drawable.unlock_icon);
}
builder.setView(view).setCancelable(true);
dialog = builder.create();
dialog.setView(view, 0, 0, 0, 0);
timerDelayRemoveDialog(time, dialog);
dialog.show();
但仍显示为
but still it appears as
我曾尝试在堆栈上流动提供的所有帮助。
I have tried all the help provided at the stack over flow
<一个href=\"http://stackoverflow.com/questions/4710025/how-to-set-transparent-background-for-image-button-in-$c$c\">Setting ImageView的背景透明,
Setting通过#8000 透明度以及
但他们没有工作,但它仍然显示出来。
But none of them worked, it still showing up.
推荐答案
或者你可以使用Dialog类此,
Or you can use Dialog class for this,
Dialog dialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar);
Window window = dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
window.setLayout(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setContentView(R.layout.temp);
dialog.show();
这篇关于要设置自定义布局的背景与ImageView的为透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!