2

I'm using progress bar in my android application. it is visible on most of the API's except API 23 (Marshmallow). I used to display it on fragment transition using following code

mProgressBar.setVisibility(View.GONE)
mProgressBar.setVisibility(View.VISIBLE)

i have used following code

<ProgressBar
        android:id="@+id/progress"
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:padding="15dp"
        android:layout_marginEnd="5dp"
        android:layout_marginRight="5dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:visibility="gone"
        android:indeterminateTint="@color/colorGreen"
        android:indeterminateTintMode="src_in"
        android:indeterminate="true" />

I have checked it on emulator and also on device.

Please provide solution.

Fragment Transition is done as follows,

On Button click of first fragment(MSHCFragment) passed data using bundle

mDataPassListener.onMSHCDataPass(bundle);

where mDataPassListener is object of onMSHCDataPassListener interface

where the following interface defined in MSHCFragment

public interface onMSHCDataPassListener{

        void onMSHCDataPass(Bundle bundle);
    }

this listener intialized as follows in same,

@Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;
            mDataPassListener = (onMSHCDataPassListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

the above interface implemented in MainActivity, and onMSHCDataPass code in MainActivity as follows,

@Override
    public void onMSHCDataPass(Bundle bundle) {
        MSHCRptFragment fragment = (MSHCRptFragment) getSupportFragmentManager().findFragmentById(R.id.mshcmain);

        if (fragment != null) {

     }
 else {

            MSHCRptFragment fragment1 = new MSHCRptFragment();
            Bundle args = new Bundle();
            args.putAll(bundle);
            fragment1.setArguments(args);
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            mViewPager.setPagingEnabled(false);
            transaction.replace(R.id.frag_mainlayout1, fragment1);
            transaction.addToBackStack(null);
            transaction.commit();
        }
    }
meetme
  • 43
  • 6

1 Answers1

2

Updated Progress bar code

<ProgressBar
        android:id="@+id/progressb"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:layout_height="100dp"
        android:layout_width="100dp"
        android:visibility="gone"
        style="?android:attr/progressBarStyleLarge"
        android:progressDrawable="@drawable/myprogress1"
        android:indeterminateDrawable="@drawable/myprogress1"
        app:layout_constraintDimensionRatio="1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.542" />

as you can see, i have added following attributes to progress bar

   style="?android:attr/progressBarStyleLarge"
   android:progressDrawable="@drawable/myprogress1"
   android:indeterminateDrawable="@drawable/myprogress1"

myprogress1.xml is as follows,created this drawable file in drawable folder under res in android studio

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360"
    android:duration="1">

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false">

        <size
            android:height="48dip"
            android:width="48dip" />

        <gradient
            android:centerColor="#AAFFCC"
            android:centerY="0.50"
            android:endColor="#78cc00"
            android:startColor="#55cc33"
            android:type="sweep"
            android:angle="270"
            android:useLevel="false" />

    </shape>

</rotate> 

and called visible and gone as per required i.e. mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.VISIBLE);

meetme
  • 43
  • 6