gpt4 book ai didi

android - CalendarView android 中的小数字

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:59:24 25 4
gpt4 key购买 nike

我的应用程序需要 CalendarView。但是天数很少。如何让它们变大?

CalendarView

最佳答案

如果有人仍然感兴趣,这是我根据 Phil 的帖子中提供的信息和 XSJoJo 的报告得出的解决方案。如此处所述,存在问题是因为 mDateTextSize 未分配给 CalendarViewLegacyDelegate 中的 mMonthNumDrawPaint。我正在使用 Java 反射。

    /**
* I'm doing this in my fragment's onCreateView() callback
*/

CalendarView calendarView = (CalendarView) contentView.findViewById(R.id.calendar_view);

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) { // this bug exists only in Android 4.1
try {
Object object = calendarView;
Field[] fields = object.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.getName().equals("mDelegate")) { // the CalendarViewLegacyDelegate instance is stored in this variable
field.setAccessible(true);
object = field.get(object);

break;
}
}

Field field = object.getClass().getDeclaredField("mDateTextSize"); // text size integer value
field.setAccessible(true);
final int mDateTextSize = (Integer) field.get(object);

field = object.getClass().getDeclaredField("mListView"); // main ListView
field.setAccessible(true);
Object innerObject = field.get(object);

Method method = innerObject.getClass().getMethod(
"setOnHierarchyChangeListener", ViewGroup.OnHierarchyChangeListener.class); // we need to set the OnHierarchyChangeListener
method.setAccessible(true);
method.invoke(innerObject, (Object) new ViewGroup.OnHierarchyChangeListener() {
@Override
public void onChildViewAdded(View parent, View child) { // apply text size every time when a new child view is added
try {
Object object = child;
Field[] fields = object.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.getName().equals("mMonthNumDrawPaint")) { // the paint is stored inside the view
field.setAccessible(true);
object = field.get(object);
Method method = object.getClass().
getDeclaredMethod("setTextSize", float.class); // finally set text size
method.setAccessible(true);
method.invoke(object, (Object) mDateTextSize);

break;
}
}
} catch (Exception e) {
Log.e(APP_TAG, e.getMessage(), e);
}
}

@Override
public void onChildViewRemoved(View parent, View child) {}
});
} catch (Exception e) {
Log.e(APP_TAG, e.getMessage(), e);
}
}

关于android - CalendarView android 中的小数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14980242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com