2012-02-23 17 views
9

मैं अपने एप्लिकेशन में कैलेंडरव्यू जोड़ने की कोशिश कर रहा हूं, जो थीम का उपयोग करता है। लाइट थीम। समस्या यह है कि, इस कैलेंडर की दिन संख्या सफेद में प्रस्तुत की जाती है, इसलिए एक हल्की थीम का उपयोग करते समय, आप उन्हें नहीं देख सकते हैं।कैलेंडर दृश्य शैली बदलें

अभी, मैं अपने एक्सएमएल लेआउट फ़ाइल में निम्न कोड है:

<CalendarView 
    android:id="@+id/calendar1" 
    android:layout_width="500dp" 
    android:layout_height="300dp"/> 

मैं इस तरह कैलेंडर विषय के लिए मजबूर करने की कोशिश की:

<CalendarView 
    android:id="@+id/calendar1" 
    android:layout_width="500dp" 
    android:layout_height="300dp" 
    android:theme="@android:style/Theme.Light" /> 

लेकिन यह कुछ भी नहीं बदलता है। मुझे लगता है मैं एंड्रॉयड के साथ कुछ करना चाहिए: dateTextAppearance संपत्ति है, इसलिए मैं इस कोशिश की:

<CalendarView 
    android:id="@+id/calendar1" 
    android:layout_width="500dp" 
    android:layout_height="300dp" 
    android:dateTextAppearance="@android:style/TextAppearance.Large.Inverse" /> 

लेकिन यह या तो कुछ भी नहीं है।

कोई विचार?

धन्यवाद!

उत्तर

28

मेरी प्रोजेक्ट में मैंने अपनी थीम में "एंड्रॉइड: कैलेंडरव्यू स्टाइल" विशेषता को परिभाषित किया।

<style name="Theme.Custom" parent="@android:Theme"> 
    <item name="android:calendarViewStyle">@style/Widget.CalendarView.Custom</item> 
</style> 

<style name="Widget.CalendarView.Custom" parent="android:Widget.CalendarView"> 
    <item name="android:focusedMonthDateColor">@color/cs_textcolor</item> 
    <item name="android:weekNumberColor">@color/red</item> 
    <item name="android:weekDayTextAppearance">@style/TextAppearance.Medium</item> 
    <item name="android:dateTextAppearance">@style/TextAppearance.Medium</item> 
</style> 

सभी शैलियों संभावनाएं हैं:

  • @attr android.R.styleable रेफरी # CalendarView_showWeekNumber
  • @attr रेफरी android.R.styleable # CalendarView_firstDayOfWeek
  • @attr रेफरी android.R । स्टाइलबल # कैलेंडरव्यू_मिनडेट
  • @attr ref android.R.styleable # कैलेंडरव्यू_मैक्सडेट
  • @attr ref & roid.R.styleable # CalendarView_shownWeekCount
  • @attr android.R.styleable रेफरी # CalendarView_selectedWeekBackgroundColor
  • @attr रेफरी android.R.styleable # CalendarView_focusedMonthDateColor
  • @attr रेफरी android.R.styleable # CalendarView_unfocusedMonthDateColor
  • @ attr android.R.styleable # CalendarView_weekNumberColor रेफरी
  • @attr android.R.styleable रेफरी # CalendarView_weekSeparatorLineColor
  • @attr रेफरी android.R.styleable # CalendarView_selectedDateVerticalBar
  • @attr रेफरी android.R.styleable # CalendarView_weekDayTextAppearance
  • @attr android.R.styleable रेफरी # CalendarView_dateTextAppearance

ध्यान दें: यदि showWeekNumber नहीं एक्सएमएल शैली के रूप में काम करते हैं, आप setShowWeekNumber साथ कोड में सेट कर सकते हैं (सच)।

+0

क्या यह सही है?

+2

उपरोक्त समाधान –

+0

का उपयोग कर रंग थीम बदलने में असमर्थ क्या आप इस पर थोड़ा और विस्तार कर सकते हैं? मैं उन सभी "@attr" सामग्री का उपयोग कहां करूं? मैं उससे बिल्कुल परिचित नहीं हूँ। –

5

मुझे भी बहुत परेशानी हो रही है। हालांकि सही नहीं है, और मुझे पता नहीं चला कि हर पहलू को कैसे संशोधित किया जाए, मैं करीब आ गया। परियोजना की शैलियों में मैंने ऐसा किया है।

<CalendarView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:theme="@style/CalenderViewCustom" 
    android:dateTextAppearance="@style/CalenderViewDateCustomText" 
    android:weekDayTextAppearance="@style/CalenderViewWeekCustomText"/> 

आप रंग के अन्य प्रकार जोड़ सकते हैं (प्राथमिक/माध्यमिक) के ऊपर CalenderViewCustom रहे हैं: CalendarView मैं के रूप में इसलिए उन शैलियों संदर्भित के लिए फिर

<style name="CalenderViewCustom" parent="Theme.AppCompat"> 
    <item name="colorAccent">@color/white_30</item> 
</style> 

<style name="CalenderViewDateCustomText" parent="android:TextAppearance.DeviceDefault.Small"> 
    <item name="android:textColor">@color/white</item> 
</style> 

<style name="CalenderViewWeekCustomText" parent="android:TextAppearance.DeviceDefault.Small"> 
    <item name="android:textColor">@color/white_30</item> 
</style> 

,: एक्सएमएल मैं इन दोनों शैली गयी।