改变Spinner的外观

3

首先请查看这张图片:

enter image description here

它展示了一个美观而漂亮的Spinner,我的Spinner看起来像这样:

enter image description here

以下是我所有的源代码。

Activity xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="amaz1ngc0de.com.br.spinnertest.MainActivity">

    <Spinner
        android:id="@+id/sp_paymentType"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >

    </Spinner>

</RelativeLayout>

我的问题是:如何实现教程中展示的相同布局?
PS:我已经查看了这个主题:Correct usage of a Spinner, following material design guidelines,它提到了主题,但我无法使其工作,我正在遵循的教程是这个:Spinners
1个回答

7

很遗憾,您的教程已经过时了。您展示的第一张截图是Holo样式的。而您所创建的则采用了更新、更好的Material Design。干得好,您胜过了这个教程!

然而,如果您真的想要达到相同的效果,您可以将您的活动设置为使用Holo主题,这样就可以回到旧的外观。您可以在AndroidManifest.xml中进行设置:

<activity
    android:name="..."
    android:theme="@android:style/Theme.Holo.Light" />

如果您使用自定义主题,则将其设置为父级:

<style name="AppTheme" parent="android:Theme.Holo.Light">

如果您只想更改Spinner的外观,而不是整个屏幕,可以在Spinner上使用android:theme

<Spinner
    android:id="@+id/sp_paymentType"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:theme="@android:style/Theme.Holo.Light">


2
你很棒,只需改进你的答案,就可以使用标签“theme”在“Spinner”中更改主题。 - guisantogui
我个人建议整个应用程序保持一个视觉风格。但你完全是正确的,如果你只是想改变旋转器,那么这就是你要做的。 - Marcin Koziński

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接