设置日历视图月份名称的文本颜色 [英] Set the text color of calendar view month name

查看:152
本文介绍了设置日历视图月份名称的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android中,我使用的是默认CalendarView。
我已经将背景设置为浅灰色的颜色。但我可以改变日历视图月视图的颜色?

In android , i am using an default CalendarView. I have set the background to light gray color. But can i change the color of month view of calendar view?

推荐答案

正如你所发现,TextView的是私有的,而且似乎没有任何方法来访问它。

As you've found out, the TextView is private, and there does not seem to be any methods for accessing it.

虽然我不会推荐它,你可以使用的java.lang.reflect 封装实现这一点:

Although I wouldn't recommend it, you can accomplish this using the java.lang.reflect package:

    try
    {
        CalendarView cv = (CalendarView) this.findViewById(R.id.calendarView1);
        Class<?> cvClass = cv.getClass();
        Field field = cvClass.getDeclaredField("mMonthName");
        field.setAccessible(true);

        try
        {
            TextView tv = (TextView) field.get(cv);
            tv.setTextColor(Color.RED);
        } 
        catch (IllegalArgumentException e)
        {
            e.printStackTrace();
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }
    }
    catch (NoSuchFieldException e)
    {
        e.printStackTrace();
    }

这篇关于设置日历视图月份名称的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆