質問

I found 2 built-in NumberPickers:


(source: techbooster.org)

By default, it's the first one, but when I add android:theme="@android:style/Theme.NoTitleBar" in AndroidManifest.xml, it becomes the second one.

How can I put this line (I need it) and still get the first NumberPicker?

役に立ちましたか?

解決 2

you are setting the non holo theme so you get the non holo numberpicker.

see this as reference, its basically the same thing you asked

Remove titlebar in xml

他のヒント

The problem is that @android:style/Theme is the Android theme for devices on API version 10 (2.3) and lower.

If you want to keep Holo support, you should use @android:style/Theme.Holo.

If you need to support devices without Holo as well, you will need to create asset folders for those devices and specify the theme there.

You can use:

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

if you don't want to display the ActionBar and still get Holo-styled NumberPicker.

Have a superclass named as BaseActivity which gets extended by all the activities in your app. In it's onCreate call this

requestWindowFeature(Window.FEATURE_NO_TITLE);

It'll remove the title bar from all of your activities and you can use whatever theme you want. The only drawaback you'll get is the title bar will appear for a fraction of second when launching your app, but won't be seen again.

Additionally you can change also the following properties:

Your numberpicker definition in exampleActivity.xml

<NumberPicker
<!-- ... -->
android:background="@drawable/customshape" />

The drawable/customshape.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
    android:startColor="@color/numberpicker_color_range_start"
    android:endColor="@color/numberpicker_color_range_end"
    android:angle="270"/>
</shape> 

solidColor ... is the main holo color and a background with a customshape to get additional coloring:

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top