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

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

问题描述

所以问题很简单:

我在我的应用程序中集成了一个 DatePicker.不是作为 DialogDatePicker 而是作为视图组件(更准确地说是 Fragment 内的 View,它动态显示并从 FrameLayout 包含在我的主要 FragmentActiviy 布局中.).

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.).

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

now my problem is that this DataPicker looks like this:

而不是这样:

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

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.

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

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?

任何帮助将不胜感激.

谢谢.

代码:

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 类:

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;
    }
}

更新:

Manifast 文件:

<?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"

创建以下 DataPicker:

Creates the following DataPicker:

比以前好多了,但这仍然不是我想要的结果.

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

推荐答案

将您的 android:targetSdkVersion 设置为 11 或更高.这是一个演示此内容的示例应用.

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

更新

首先,您的原始 DatePicker 屏幕截图来自深色主题(例如 Theme.Holo),而您的第二个屏幕截图来自浅色主题(例如 Theme.Holo.Light).

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).

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

Second, the DatePicker documentation has the following opening paragraph:

这个类是一个用于选择日期的小部件.可以通过年、月和日微调器或 CalendarView 选择日期.一组微调器和日历视图会自动同步.客户端可以自定义是只显示微调器,还是只显示日历视图,或两者都显示.还可以自定义选择日期的最小和最大日期.

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.

您可以通过android:calendarViewShown(或setCalendarViewShown())去掉CalendarView.当您尝试这样做时,您会发现一旦 CalendarView 消失,您的年份微调器就会出现.

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天全站免登陆