AppCompat v7和DatePicker渲染问题

时间:2016-01-30 10:29:47

标签: android android-studio intellij-idea datepicker android-appcompat

最近我在 The Big Nerd Ranch Guide(第2版)中读到了关于对话框的章节,我已经完成了本书的所有内容。然而,有一些问题,这些问题没有在书中得到满足。 Intellij Idea 的预览区域无法与AppCompat主题一起正常工作。

这是我目前的主题:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
     <!-- Customize your theme here. -->
</style>

这就是我在预览区域中所拥有的: enter image description here

在互联网上,我已经读到使用 Base.Theme.AppCompat.Light.DarkActionBar 可能有所帮助。它删除了消息,但ActionBar也消失了。

哦, DatePicker 不适用于任何 Material Design enter image description here

这只是一个渲染问题,因为这两个主题在设备上运行良好。 有人可以尝试使用AppCompat主题在IDEA和Android Studio中预览DatePicker吗?可能这只是一个IDEA问题。

P.S。 dialog_date.xml

<?xml version="1.0" encoding="utf-8"?>
<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/dialog_date_date_picker"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:calendarViewShown="false"
/>

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.criminalintent" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
                android:name=".CrimeListActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".CrimePagerActivity"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

整个项目: https://onedrive.live.com/redir?resid=4653F2D263EA4131!21585&authkey=!AESze90_ZZ0p9WY&ithint=folder%2cproperties

3 个答案:

答案 0 :(得分:1)

让你的style.xml看起来像这样,工具栏会显示出来:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
     <!-- Customize your theme here. -->
</style>
<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
</style>

您的 DatePicker 需要像这样:

<DatePicker
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:datePickerMode="spinner"
    android:id="@+id/datePicker" />

如果您的xml中需要 CalendarView ,请添加 DatePicker

<CalendarView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/calendarView1" />

答案 1 :(得分:1)

切换主题

如果您查看Theme.AppCompat.Light.DarkActionBar的声明,它会直接别名为AppCompat的values / themes.xml文件中的Base.Theme.AppCompat.Light.DarkActionBar

<!-- Platform-independent theme providing an action bar in a dark-themed activity. -->
<style name="Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar" />

source

这在任何其他设备配置中都没有别名(例如,值-v23 / themes.xml,values-v18 / themes.xml等)。查看AppCompat here的资源。这意味着,对于每个设备,Theme.AppCompat.Light.DarkActionBar始终别名Base.Theme.AppCompat.Light.DarkActionBar

Base主题的文档使这一点更加清晰:

  

主题&#34; Base.Theme&#34;家庭因当前而异   平台版本为每台设备提供正确的基础。您   可能不想直接在您的应用中使用它们。

     

&#34; Theme.AppCompat&#34;中的主题家庭意味着延长或   由应用程序直接使用。

source

因此,从Theme.AppCompat.Light.DarkActionBar切换到Base.Theme.Light.DarkActionBar永远不会影响事物在实际设备上的显示方式,也不会发生变化。 Android Studio表现不同的事实是Android Studio的问题(我无法使用您在AS 2.0预览9上的代码重现)。

Android Studio

的问题

我说设计标签总是有点不稳定。它变得越来越好但并不总是很好玩,尤其是支持库的东西。要改变你的应用程序的主题(即使我上面说的不是真的)只是让设计选项卡看起来漂亮可能是一个坏主意。想想你的用户。如果确实想要了解屏幕的外观,请将其部署到真实设备或模拟器。

对话框

我也无法在AS 1.4(稳定版)或AS 2.0预览版9(金丝雀,ATM)中重现您的Dialog问题。但由于您的整个布局文件是DatePicker,因此我认为您不会获得太多好处。如果您认为DatePicker将显示在对话框中(“设计”选项卡无法模拟),则效果会更差。我并不意味着听起来很苛刻,但你可能只需咬紧牙关并使用仿真器或物理设备。

答案 2 :(得分:0)

Shitty Android Studio 1.5.0应该更新到1.5.1。很容易