2016-07-26 14 views
0

Wenn DatePicker mit Kalenderansicht angezeigt wird, ist es möglich, zusätzliche Beschriftung mit etwas Text am Ende dieser Kalenderansicht (wie auf dem Bild gezeigt) zu haben? Ich habe versucht zu suchen, ob es eine Möglichkeit gibt, original Android DatePicker anzupassen, kann keine geeignete Methode sehen, es zu tun.Android DatePicker Layoutanpassung

datepicker

Antwort

3

Sie können den Quellcode von here erhalten.

Um das Layout wie gewünscht anzupassen, sollten Sie layout-land/mdtp_date_picker_dialog.xml und layout-sw600dp-land/mdtp_date_picker_dialog.xml Felder ändern. Hier habe ich zwei TextViews als Screenshot hinzugefügt:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@color/mdtp_background_color" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="450dp" 
     android:gravity="center" 
     android:orientation="horizontal"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:orientation="vertical"> 

      <include layout="@layout/mdtp_date_picker_header_view" /> 

      <include layout="@layout/mdtp_date_picker_selected_date" /> 

      <include layout="@layout/mdtp_date_picker_footer_view" /> 

      <TextView 
       android:id="@+id/added_text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:padding="8dp" 
       android:text="Some Text" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:orientation="vertical"> 

      <include layout="@layout/mdtp_date_picker_view_animator" /> 

      <TextView 
       android:id="@+id/added_text2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Some text" /> 
     </LinearLayout> 

    </LinearLayout> 

    <include layout="@layout/mdtp_done_button" /> 
</LinearLayout> 

Änderung im Zusammenhang dimens die TextViews zu lokalisieren, wie Sie wollen.

+0

Noch arbeiten daran, aber sieht aus wie es ist, was ich brauche. Vielen Dank. – etilia

+0

Ist dies garantiert in zukünftigen Versionen von Android nicht zu brechen? Ich habe keine offizielle API von Android gesehen. – Dibzmania

0

Ich hatte vor einer Weile ein ähnliches Problem konfrontiert. Ich würde Ihnen empfehlen, this Bibliothek zu verwenden.

Sie können diese Bibliothek auf beliebige Weise anpassen. Bearbeiten Sie einfach seine Layout-Datei und erweitern Sie das gewünschte Layout. Sie können Beschriftungen auch einfach in den Layoutdateien hinzufügen.

Ich hoffe, es hilft.