代码之家  ›  专栏  ›  技术社区  ›  Ali Ha Quang

对话活动-自定义主题

  •  0
  • Ali Ha Quang  · 技术社区  · 7 年前

    我一直试图在活动对话框中实现一个自定义主题,目标是

    enter image description here

    我在展示 Progressbar 在关闭“活动”和“我的活动”对话框之前15秒,如下所示

    enter image description here

    尽管它正在做它应该做的事情,但我仍然没有得到以下结果

    一。 背景是“ 透明的 “我希望它像第一张截图一样完全透明

    2. 我把活动称为 ExcludeFromRecents = true 但它仍然显示在 最近的应用程序 在这15秒内列出

    现在说到代码,

    我的对话框布局如下- DialogActivityLayout

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="bottom|center" 
        android:gravity="bottom"
        android:orientation="vertical" >
      <ProgressBar
            android:id="@+id/progressRecicer"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"       
             android:layout_gravity="bottom|center"
            android:gravity="bottom"/>   
    </RelativeLayout>
    

    我的对话主题样式如下 styles.xml

    <style name="AppCompatDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>   
      </style>
    

    我的活动代码如下

    [Activity(Label = "Dialog Activity", MainLauncher = false, Theme = "@style/AppCompatDialogTheme", ExcludeFromRecents = true)]
    

    我的活动 OnCreate(Bundle savedInstanceState) 方法如下

    base.OnCreate(savedInstanceState);
    SetContentView(Resource.Layout.DialogActivityLayout);
    Window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));
    this.SetFinishOnTouchOutside(false);
    this.SetTheme(Resource.Style.AppCompatDialogTheme);
    Toast.MakeText(this, "Dialog Activity Opened", ToastLength.Long).Show();
    Handler h = new Handler();
    Action myAction = () =>
    {
      Finish();
    };
    h.PostDelayed(myAction, 15000);
    

    我们非常感谢为实现这两个目标所提供的任何帮助

    1 回复  |  直到 7 年前
        1
  •  1
  •   Sarthak Gandhi    7 年前

    要减少调光量,您必须使用:

    WindowManager.LayoutParams layoutParams = progressDialog.getWindow().getAttributes();
    layoutParams.dimAmount = 0.5f; //Ranges from 0 to 1.
    progressDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    progressDialog.getWindow().setAttributes(layoutParams);
    

    所以你只需要把它设置为0。

    希望这有帮助。

    推荐文章