DataPicker看起来像是新API上的旧设计 [英] DataPicker looks like old design on new API's as well

查看:148
本文介绍了DataPicker看起来像是新API上的旧设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以问题很简单:



我已经在我的应用程序中集成了一个 DatePicker
不是一个 DialogDatePicker ,而是作为一个View组件(更准确地说是一个 View $ c> Fragment ,它是从我的主要 FragmentActiviy FrameLayout 中动态显示和删除的>布局。)



现在我的问题是这个DataPicker看起来像这样:



而不是这样:





即使我将目标更高的API,我尝试将我的Min SDK设置为16或17,但也没有任何帮助。



有些人知道为什么会这样发生?以及如何显示数据选择器的新外观?
最好在旧版本的Android上?



任何帮助将不胜感激。



谢谢



编辑:代码:



DataPickerFragment xml: strong>

 <?xml version =1.0encoding =utf-8?> 
< FrameLayout xmlns:android =http://schemas.android.com/apk/res/android
android:layout_width =wrap_content
android:layout_height =wrap_content
android:orientation =vertical
android:paddingLeft =6.5dp
android:paddingTop =6dp
android:paddingRight =8.5dp
android:paddingBottom =8.5dp
android:background =@ drawable / date_picker_background>

< DatePicker
android:id =@ + id / datePicker
android:layout_width =match_parent
android:layout_height =wrap_content
android:layout_margin =10dp
android:paddingBottom =40dp/>

< LinearLayout
android:layout_width =match_parent
android:layout_height =match_parent>

< Button
android:id =@ + id / bCancel
android:layout_width =match_parent
android:layout_height =wrap_content
android:layout_gravity =bottom
android:layout_weight =1.0
android:onClick =buttonCanceDatePickerOnclick
android:text =@ string / cancel/>

< Button
android:id =@ + id / bSave
android:layout_width =match_parent
android:layout_height =wrap_content
android:layout_gravity =bottom
android:layout_weight =1.0
android:onClick =buttonSaveDatePickerOnclick
android:text =@ string / save/>

< / LinearLayout>
< / FrameLayout>

DataPickerFramgnet类:

  public class DatePickerFragment extends Fragment {

private Button bSave,bCancel;

public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup容器,
Bundle savedInstanceState){
查看rootView = inflater.inflate(R。 layout.date_picker_fragment_layout,
container,false);
返回rootView;
}
}

更新: p>

Manifast文件

  xml version =1.0encoding =utf-8?> 
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =com.emildesign.sgreportmanager
android:versionCode = 1
android:versionName =1.0>

< uses-sdk
android:minSdkVersion =13
android:targetSdkVersion =17/>

< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>
< uses-permission android:name =android.permission.ACCESS_NETWORK_STATE/>
< uses-permission android:name =android.permission.INTERNET/>
< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>

<! - Crittercism - >
< uses-permission android:name =android.permission.READ_LOGS/>
< uses-permission android:name =android.permission.GET_TASKS/>

< application
android:allowBackup =true
android:name =com.emildesign.sgreportmanager.SGRaportManagerAppObj
android:icon =@ drawable / ic_launcher
android:label =@ string / app_name
android:theme =@ android:style / Theme.Black.NoTitleBar.Fullscreen>

< activity
android:name =com.emildesign.sgreportmanager.activities.LoginScrActivity
android:screenOrientation =landscape>

< intent-filter>
< action android:name =android.intent.action.MAIN/>
< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< activity
android:name =com.emildesign.sgreportmanager.activities.ReportsTableActivity
android:screenOrientation =landscape>
< / activity>
< activity
android:name =com.emildesign.sgreportmanager.activities.ParametersActivity
android:screenOrientation =landscape>
< / activity>
< activity android:name =com.crittercism.NotificationActivity/>
< / application>



我发现我的问题是,我设置:

  android:theme =@ android:style / Theme.Black.NoTitleBar.Fullscreen

将我的应用程序全屏显示,并应用旧样式的数据选择器将其更改为:

  android:theme =@ android:style / Theme.Holo.Light.NoActionBar.Fullscreen

创建以下DataPicker:





以前比以前更好,但这还不是我正在寻找的结果

解决方案

将您的 android:targetSdkVersion 设置为11或更高。 以下是演示此示例的示例应用程序






更新



首先,您的原始 DatePicker 截图是从一个黑暗的主题(例如, Theme.Holo ),而你的第二个屏幕截图来自一个轻的主题(例如, Theme.Holo.Light )。



其次, DatePicker 文档有以下开头的段落:


此类是一个用于选择日期的小部件。日期可以由年,月和日的纺织品或CalendarView选择。旋转机组和日历视图将自动同步。客户端可以自定义是否只显示纺纱器,或仅定义日历视图,或两者都可以进行显示。此外,可以自定义要选择的日期的最小和最大日期。


您可以摆脱 CalendarView 通过 android:calendarViewShown (或 setCalendarViewShown())。当您尝试时,您会发现,一旦 CalendarView 消失,您的年份微调器就会出现。


So the problem is very simple:

I have integrated a DatePicker in my application. Not as a DialogDatePicker but as a View component (more precisely a View inside of a Fragment that is dynamically shown and removed from a FrameLayout contained in my main FragmentActiviy layout.).

now my problem is that this DataPicker looks like this:

and not like this:

even when I target the higher API's, I tried setting my Min SDK to 16 or 17 as well but it didn't do any help either.

Some one know why it happens? and how can I show the new look of the data picker? preferably on old versions of Android as well?

Any help would be appreciated.

Thanks.

EDIT: code:

DataPickerFragment xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingLeft="6.5dp"
    android:paddingTop="6dp"
    android:paddingRight="8.5dp"
    android:paddingBottom="8.5dp"
    android:background="@drawable/date_picker_background">

    <DatePicker
        android:id="@+id/datePicker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:paddingBottom="40dp" />

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/bCancel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_weight="1.0"
            android:onClick="buttonCanceDatePickerOnclick"
            android:text="@string/cancel" />

        <Button
            android:id="@+id/bSave"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_weight="1.0"
            android:onClick="buttonSaveDatePickerOnclick"
            android:text="@string/save" />

     </LinearLayout>
</FrameLayout>

DataPickerFramgnet class:

public class DatePickerFragment extends Fragment {

    private Button bSave, bCancel;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.date_picker_fragment_layout, 
                                         container, false);
        return rootView;
    }
}

UPDATE:

Manifast file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.emildesign.sgreportmanager"
android:versionCode="1"
android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <!--  Crittercism  -->
    <uses-permission android:name="android.permission.READ_LOGS"/>
    <uses-permission android:name="android.permission.GET_TASKS"/>

    <application
        android:allowBackup="true"
        android:name="com.emildesign.sgreportmanager.SGRaportManagerAppObj"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

        <activity
            android:name="com.emildesign.sgreportmanager.activities.LoginScrActivity"
            android:screenOrientation="landscape">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.emildesign.sgreportmanager.activities.ReportsTableActivity"
            android:screenOrientation="landscape">
        </activity>
        <activity
            android:name="com.emildesign.sgreportmanager.activities.ParametersActivity"
            android:screenOrientation="landscape">
        </activity>
        <activity android:name="com.crittercism.NotificationActivity"/>  
</application>

well I found where my problem was, I set:

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 

to make my application full screen and this applied the old style of the data picker changing it to:

android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"

Creates the following DataPicker:

It's better then before but this is still not the result I'm looking for.

解决方案

Set your android:targetSdkVersion to be 11 or higher. Here is a sample application demonstrating this.


UPDATE

First, your original DatePicker screenshot is from a dark theme (e.g., Theme.Holo), whereas your second screenshot is from a light theme (e.g., Theme.Holo.Light).

Second, the DatePicker documentation has the following opening paragraph:

This class is a widget for selecting a date. The date can be selected by a year, month, and day spinners or a CalendarView. The set of spinners and the calendar view are automatically synchronized. The client can customize whether only the spinners, or only the calendar view, or both to be displayed. Also the minimal and maximal date from which dates to be selected can be customized.

You can get rid of the CalendarView via android:calendarViewShown (or setCalendarViewShown()). When you try that, you will find that your year spinner will appear once the CalendarView is gone.

这篇关于DataPicker看起来像是新API上的旧设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆