Показывать только сегодняшнюю дату в CalendarView - PullRequest
0 голосов
/ 28 июня 2018

enter image description here

Как мне отобразить CalendarView без календаря?

Мне не нужен календарь.

enter image description here

Может кто-нибудь, пожалуйста, помогите мне, я не могу понять это. Спасибо.

Ответы [ 3 ]

0 голосов
/ 28 июня 2018

Просто используйте TextView и установите текст на нем следующим образом:

String myFormat = "dd-MMM-yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
textView.setText(sdf.format(Calendar.getInstance().getTime()));

Надеюсь, это поможет.

0 голосов
/ 28 июня 2018

Так как я не смог сделать это с существующим компонентом, я сделал пользовательское представление.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="7dp">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:contentDescription="@string/previous_date"
    android:src="@drawable/ic_previous_date_gray_24dp"
    android:onClick="previousDate"
    />

<TextView
    android:id="@+id/dateText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="2015-06-18" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:contentDescription="@string/next_date"
    android:src="@drawable/ic_next_day_gray_24dp"
    android:onClick="nextDate"
    />

</RelativeLayout>
0 голосов
/ 28 июня 2018

Попробуйте добавить строку ниже в xml

android:calendarViewShown="false"

в DatePicker.

...