问题
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
Setting ImageView background to transparent,
Setting transparency by #80000000 and
Setting Dialog window transparency
But none of them worked, it still showing up.
回答1:
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();
回答2:
Try using this as the style of your View :
<style name="Dialog_Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
来源:https://stackoverflow.com/questions/11608377/to-set-background-of-custom-layout-with-an-imageview-to-transparent