使用ImageView将自定义布局的背景设置为透明

时间:2012-07-23 07:51:27

标签: android android-layout android-dialog

我正在使用Android开发人员文档link构建自定义对话框,为此我制作了一个布局文件

<?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>

我正在给这个对话框充气,

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();

但仍显示为 how dialog appears

我已经尝试了堆栈上提供的所有帮助

Setting ImageView background to transparent

Setting transparency by #80000000

Setting Dialog window transparency

但它们都没有奏效,它仍然出现。

2 个答案:

答案 0 :(得分:2)

或者你可以使用Dialog类,

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();

答案 1 :(得分:1)

尝试将其用作视图的样式:

<style name="Dialog_Fullscreen">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowNoTitle">true</item>
</style> 
相关问题