input
input

Reputation: 7519

Set weekdays programmatically

I am using w2davids calendar and in that calendar, the author of the code has used an image (ImageView) to display the weekdays:

<LinearLayout
    android:layout_gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/calendarheader"
        android:src="@drawable/blue_bg_with_text"
        android:layout_gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </ImageView> 
</LinearLayout>

enter image description here

I would not like to use an image for the weekdays. How can I set it programmatically?

Upvotes: 0

Views: 322

Answers (1)

Cat
Cat

Reputation: 67502

Create a horizontal LinearLayout with seven TextViews. You can set their contents using DateUtils.getDayOfWeekString(). (I'm not sure if that DateUtils method is locale-compliant; if it's not, try this method.)

In terms of formatting, using a center gravity on each TextView and a large upper padding on the LinearLayout should work fine, and you can set the background to whatever you need using a drawable.

Upvotes: 3

Related Questions