API 23 上的进度条不工作或不可见
Progress bar not working or invisible on API 23
我在 android 应用程序中使用进度条。除了 API 23(棉花糖)外,它在大多数 API 上都可见。我曾经使用以下代码在片段转换中显示它
mProgressBar.setVisibility(View.GONE)
mProgressBar.setVisibility(View.VISIBLE)
我使用了以下代码
<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" />
我已经在模拟器和设备上检查过了。
请提供解决方案。
Fragment Transition是这样完成的,
在按钮单击第一个片段 (MSHCFragment) 时使用 bundle 传递数据
mDataPassListener.onMSHCDataPass(bundle);
其中 mDataPassListener 是 onMSHCDataPassListener 接口的对象
其中在 MSHCFragment 中定义了以下接口
public interface onMSHCDataPassListener{
void onMSHCDataPass(Bundle bundle);
}
这个监听器初始化如下,
@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");
}
}
以上接口在MainActivity中实现,MainActivity中onMSHCDataPass代码如下,
@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();
}
}
更新进度条码
<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" />
如您所见,我在进度条中添加了以下属性
style="?android:attr/progressBarStyleLarge"
android:progressDrawable="@drawable/myprogress1"
android:indeterminateDrawable="@drawable/myprogress1"
myprogress1.xml如下,在androidstudio
res下的drawable文件夹下创建了这个drawable文件
<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>
并根据需要调用可见和消失,即 mProgressBar.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
我在 android 应用程序中使用进度条。除了 API 23(棉花糖)外,它在大多数 API 上都可见。我曾经使用以下代码在片段转换中显示它
mProgressBar.setVisibility(View.GONE)
mProgressBar.setVisibility(View.VISIBLE)
我使用了以下代码
<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" />
我已经在模拟器和设备上检查过了。
请提供解决方案。
Fragment Transition是这样完成的,
在按钮单击第一个片段 (MSHCFragment) 时使用 bundle 传递数据
mDataPassListener.onMSHCDataPass(bundle);
其中 mDataPassListener 是 onMSHCDataPassListener 接口的对象
其中在 MSHCFragment 中定义了以下接口
public interface onMSHCDataPassListener{
void onMSHCDataPass(Bundle bundle);
}
这个监听器初始化如下,
@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");
}
}
以上接口在MainActivity中实现,MainActivity中onMSHCDataPass代码如下,
@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();
}
}
更新进度条码
<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" />
如您所见,我在进度条中添加了以下属性
style="?android:attr/progressBarStyleLarge"
android:progressDrawable="@drawable/myprogress1"
android:indeterminateDrawable="@drawable/myprogress1"
myprogress1.xml如下,在androidstudio
res下的drawable文件夹下创建了这个drawable文件<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>
并根据需要调用可见和消失,即 mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.VISIBLE);