2016-07-26 45 views
0

当DatePicker与日历视图一起显示时,是否可以在此日历视图底部添加带有一些文本的附加标签(如图所示)?我试过看看是否有可能定制原始Android DatePicker,看不到任何合适的方式。Android DatePicker布局定制

datepicker

回答

3

您可以从here得到源代码。

为了自定义布局,你应该修改layout-land/mdtp_date_picker_dialog.xmllayout-sw600dp-land/mdtp_date_picker_dialog.xml fiels。在这里,我已经添加了两个TextViews为您的截图:

相关 dimens
<?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> 

变化来定位TextViews,只要你想。

+0

仍在工作,但看起来像是我需要的东西。谢谢。 – etilia

+0

这是保证不会在未来版本的Android中打破?我没有看到Android的官方API。 – Dibzmania

0

我以前遇到类似的问题。我建议你使用this库。

您可以用任何您想要的方式自定义此库。只需编辑其布局文件并展开您想要的特定布局即可。您还可以在布局文件中轻松添加标签。

希望它有帮助。