我创建了一个带有自定义 ExpandableListView
的应用。它工作正常。但我已经读到,在 Jelly Bean setIndicatorBounds
中无法正常工作。我与:
- minSdkVersion: 14
- targetSdkVersion: 18
我已经试过了,但它给了我一个错误:
调用需要 API 级别 18(当前最低为 14):android.widget.ExpandableListView#setIndicatorBoundsRelative
DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
int anchoPantalla = metrics.widthPixels;
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
expListView.setIndicatorBounds(anchoPantalla - GetDipsFromPixel(40),
anchoPantalla - GetDipsFromPixel(10));
} else {
expListView.setIndicatorBoundsRelative(anchoPantalla - GetDipsFromPixel(40),
anchoPantalla - GetDipsFromPixel(10));
}
如何修复我的错误并使我的代码在 Jelly Bean 中正常运行?谢谢
最佳答案
...
DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
int anchoPantalla = metrics.widthPixels;
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
expListView.setIndicatorBounds(anchoPantalla - GetDipsFromPixel(40),
anchoPantalla - GetDipsFromPixel(10));
} else {
JB_setIndicatorBoundsRelative(anchoPantalla - GetDipsFromPixel(40),
anchoPantalla - GetDipsFromPixel(10));
}
}
...
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void JB_setIndicatorBoundsRelative(int left, int right)
{
expListView.setIndicatorBoundsRelative(left, right);
}
关于Android:Jelly Bean 或更高版本中的 setIndicatorBounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23561025/