sup*_*rdo 13 android android-alertdialog
我有一个自定义AlertDialog样式,使AlertDialog框透明.它工作正常,除了当我将所需的透明布局膨胀到警报对话框窗口时,它显示为黑色背景.我的目标是AlertDialog让它看起来完全透明,好像只有4个按钮浮动而不是框架.图像一是自定义对话框给我的,图像二是我想要的或我的目标.
这是自定义的代码 Dialog
<style name="CustomDialog" parent="android:Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">@android:color/transparent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这就是我在我的呼唤 onCreate()
AlertDialog.Builder imageDialog = new AlertDialog.Builder(TimeLine.this, R.style.CustomDialog);
inflater = getLayoutInflater();
View view=inflater.inflate(R.layout.tabs, null);![enter image description here][1]
AlertDialog a = imageDialog.create();
a.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
a.setView(view, 0, 0, 0, 0);
a.show();
Run Code Online (Sandbox Code Playgroud)


*编辑******选项卡布局xml的代码在这里 `
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/tabLayout"
android:background="#000000ff">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2"
android:layout_marginTop="206dp"
android:layout_below="@+id/button4"
android:layout_alignStart="@+id/button4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button3"
android:layout_alignTop="@+id/button2"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button4"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="100dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="100dp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
`
从测试中看到问题的根源是什么,我发现布局是透明的,因为当我更改布局的背景颜色时,警报对话框也会改变.但是,当布局设置为透明时,似乎膨胀布局背后的内容是黑色.因此,我不确定该做什么,或者它是AlertDialog设置还是我的布局代码.
Rod*_*uin 74
问题在于它AlertDialog builder实际上不适合设计透明对话框,并且将始终具有这个实际上是它的主题的黑色背景,而是使用它Dialog来创建透明主题.
样品:
Dialog alertDialog = new Dialog(this);
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.setContentView(R.layout.tabs);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.show();
Run Code Online (Sandbox Code Playgroud)
使用Dialog对透明背景不需要任何主题操作,因此它基本上很容易.
你尝试过这样的东西:
<style name="CustomDialog" parent="@android:style/Theme.Translucent">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
...
</style>
Run Code Online (Sandbox Code Playgroud)
编辑
在java代码中试试这个
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35188 次 |
| 最近记录: |