1

システムのデフォルトテーマを利用する小さなアプリがあります。ただし、これには 2 つの問題があります。

まず、1 つのアクティビティ (TemplateView) で Android がテーマを適用しないか、アプリの他の部分とはまったく異なります。次に、ConfigurationView のスピナーとボタンもテーマの影響を受けません。

プログラムでボタンなどに触れることはありません。唯一のものは、andoird.R.layout.simple_spinner_dropdown_item を使用するスピナーの ArrayAdapter です。私が間違っていなければ、これもテーマにする必要があります。

ここで何が問題なのかを理解しようとしていますが、見つけられないようです。

私のマニフェスト

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

    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme" >
        <activity
            android:name="de.isogon.discotalker.viewController.ConfigurationController" android:theme="@android:style/Theme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity><activity android:name="de.isogon.discotalker.viewController.TemplateController"></activity>
        <activity android:name="de.isogon.discotalker.viewController.AboutController"></activity>
        <activity android:name="de.isogon.discotalker.viewController.DisplayController"></activity>

    </application>

</manifest>

ConfigurationView (ボタン/スピナーを除く通常のテーマ)

<de.isogon.discotalker.views.ConfigurationView 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" >

    <TextView
        android:id="@+id/tv_configHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/label_configuration"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <AutoCompleteTextView
        android:id="@+id/actv_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/tv_configHeader"
        android:layout_marginTop="10dp"
        android:completionThreshold="1"
        android:dropDownHeight="wrap_content"
        android:dropDownWidth="match_parent"
        android:ems="10"
        android:hint="@string/hint_text" >
    </AutoCompleteTextView>

    <ScrollView
        android:id="@+id/scrollView_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/btn_start"
        android:layout_below="@+id/actv_text" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <!-- Speed -->

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/tv_speed"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:layout_weight="1"
                    android:text="@string/label_speed" />

                <SeekBar
                    android:id="@+id/sb_speed"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:layout_weight="1" />
            </LinearLayout>

            <!-- Size -->

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/tv_size"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:layout_weight="1"
                    android:text="@string/label_size" />

                <SeekBar
                    android:id="@+id/sb_size"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:layout_weight="1" />
            </LinearLayout>

            <!-- Text Color -->

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/tv_textColor"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:layout_weight="1"
                    android:text="@string/label_textcolor" />

                <Spinner
                    android:id="@+id/sp_textcolor"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:layout_weight="1" />
            </LinearLayout>

            <!-- Text Backgroundcolor -->

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/tv_textBackgroundColor"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:layout_weight="1"
                    android:text="@string/label_textbackgroundcolor" />

                <Spinner
                    android:id="@+id/sp_textBackgroundcolor"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:layout_weight="1" />
            </LinearLayout>

            <!-- Backgroundcolor -->

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/tv_backgroundcolor"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:layout_weight="1"
                    android:text="@string/label_backgroundcolor" />

                <Spinner
                    android:id="@+id/sp_backgroundcolor"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:layout_weight="1" />
            </LinearLayout>

            <!-- Endless -->

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/tv_endless"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:layout_weight="1"
                    android:text="@string/label_endless" />

                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1" >

                    <CheckBox
                        android:id="@+id/cb_endless"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_gravity="right|center_vertical" />
                </RelativeLayout>
            </LinearLayout>

            <!-- Vibrate/Sound -->

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/tv_afterRun"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:layout_weight="1"
                    android:text="@string/label_afterRun" />

                <Spinner
                    android:id="@+id/sp_afterRun"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:layout_weight="1" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/btn_start"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="@string/button_start" />

</de.isogon.discotalker.views.ConfigurationView>

TemplateView (テーマが完全に異なる - 理由がわかりません)

<de.isogon.discotalker.views.TemplateView 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" >

    <TextView
        android:id="@+id/tv_templatesHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="10dp"
        android:text="@string/label_templates"
        android:textAppearance="?android:attr/textAppearanceLarge"
         />

    <ListView 
        android:id="@+id/lv_templateList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_templatesHeader"
        android:layout_above="@+id/rl_containerButtons">

    </ListView>

    <LinearLayout 
        android:id="@+id/rl_containerButtons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true">
        <Button 
            android:id="@+id/btn_edit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/button_edit"
            android:layout_weight="1"/>
        <Button 
            android:id="@+id/btn_delete"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/button_delete"
            android:layout_weight="1"/>
    </LinearLayout>
</de.isogon.discotalker.views.TemplateView>
4

3 に答える 3

1

問題は、getContext() メソッドを使用して最初のビューを膨張させ、getApplicationContext() を使用して他のビューを膨張させたことです。

于 2013-06-27T10:11:21.107 に答える
0

ListView の ArrayAdapter エクステンションを使用して同様の問題が発生しました。ここでの回避策は、getApplicationContext() または getContext() メソッドの代わりに MyActivity.this コンテキストを使用することです。

于 2013-09-13T22:41:21.100 に答える
0

AppCompat v22 に関連する同様の問題がありました。

アクティビティは、AppCompat テーマ (私の場合はマテリアル) を適用するために、(Activity ではなく) AppCompatActivity を拡張する必要があります。

于 2015-07-28T11:51:33.040 に答える