How can I adjust this progressbar?

JamshaidKamranJamshaidKamran PKMember ✭✭
edited May 2017 in Xamarin.Android

I am using custom dialogfragment to overlay this progressbar. but the issue is I am unable to get this transparent and I cannot remove it's edges. also the right side of the progress bar is white. why is it so? I tried my best to at least remove this white background area but I failed.

Here is my sample Code
progressidalog.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@drawable/overlay"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/overlayprogress"
        android:indeterminate="true"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/progressbar"
        android:visibility="invisible" />
</LinearLayout>

overlay.xml in drawable folder

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <layer-list>
      <item>
        <shape>
          <corners android:radius="2dp"/>
          <solid android:color="@color/modal_background"/>
        </shape>
      </item>
    </layer-list>
  </item>
</selector>

OverlayDialogFragment.cs

public class OverlayDialogFragment : DialogFragment
    {
        private ProgressBar progressbar;

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);
            SetStyle(StyleNoTitle, Resource.Style.MyDialog);
            var view = inflater.Inflate(Resource.Layout.progressdialog, container, false);
            progressbar = view.FindViewById<ProgressBar>(Resource.Id.overlayprogress);
            progressbar.Visibility = ViewStates.Visible;
            return view;
        }

        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            Dialog.Window.RequestFeature(WindowFeatures.NoTitle); // Sets an Invisible Title bar
            base.OnActivityCreated(savedInstanceState);
        }
    }

Please let me know how can I achieve a overlaying progress bar.

Answers

  • SAthukoraleSAthukorale USMember ✭✭
    edited May 2017

    In my own application I had to use the following code to make it transparent (just to put round corners). I cannot test the code right now, but check whether it helps you.

    Dialog.Window.SetBackgroundDrawable(new ColorDrawable(global::Android.Graphics.Color.Transparent));

    As for the blank right side, not sure whether this is the cause, but it could be that the parent layout's (progressidalog.axml > LinearLayout) width is set to "wrap_content" but not "match_parent".

Sign In or Register to comment.