4

現在、Holo.Light テーマでカスタム ListView アダプターを使用する際に問題が発生しています。アクティビティとフラグメント内では、すべての TextView がテーマの通常の色 ( textColorPrimary) で表示されます。ただし、カスタム ListAdapter 内のすべてのテキストはtextColorPrimary、デフォルトの Holo テーマを使用するため、実質的にテキストが判読不能になります。

これは私のアプリのメインメニューの例です:


list_main_menu.xml - ListAdapter の行レイアウト

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

    <ImageView
        android:id="@+id/imgIcon"
        android:layout_height="48dip"
        android:layout_width="48dip"
        android:src="@drawable/ic_launcher"
        />

    <TextView 
        android:id="@+id/txtFirstLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/imgIcon"
        android:text="Line 1"
        android:textSize="12pt"
        />

    <TextView
        android:id="@+id/txtSecondLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/imgIcon"
        android:layout_below="@id/txtFirstLine"
        android:text="Line 2"
        />
</RelativeLayout>

注:現在android:textColor="?android:attr/textColorPrimaryInverse"、テキストを読みやすくするために使用する必要があります。


fragment_main_menu.xml - メイン メニュー フラグメント。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="vertical" >
    <TextView
        android:id="@+id/txtWelcome"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textSize="18sp"
        />
    <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />     
</LinearLayout>

AndroidManifext.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.michaeldodd.treasurehunter"
    android:versionCode="1"
    android:versionName="0.0.1" >

    <uses-sdk android:minSdkVersion="11" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name" android:name=".gui.Login" 
            android:theme="@android:style/Theme.Holo.Light">

            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".gui.Home" android:theme="@android:style/Theme.Holo.Light" />
        <activity android:name=".gui.UserProfile" android:theme="@android:style/Theme.Holo.Light" />
        <activity android:name=".gui.MapList" android:theme="@android:style/Theme.Holo.Light" /> 
    </application>
</manifest>

現在、カスタム スタイルは使用していません。お読みいただきありがとうございます。有益なコメントをいただければ幸いです。

編集 1: 要求されたスクリーンショットは次のとおりです。 asdf 文字色を指定しないとこんな感じですが、ホロダークのデフォルトの文字色を使っているようです

asdf 手動で指定するandroid:textColor="?android:attr/textColorPrimaryInverse"とこの結果になりますが、このような回避策を使用するのは不安です。

4

2 に答える 2

23

実際のコードは投稿していませんが、まったく同じ問題が発生したContextため、カスタム アダプター コンストラクターに間違ったコードを渡していると推測されます。

私は(私のフラグメント内で)このようなことをしてきました:

dataSource = new MyCursorAdapter(getActivity().getApplicationContext(), R.layout.myrow, data,
            fields, new int[] { R.id.field1, R.id.field2 });

問題を解決するために私がしなければならなかったのは、次のものに置き換えることだけでしgetActivity().getApplicationContext()getActivity()

dataSource = new MyCursorAdapter(getActivity(), R.layout.myrow, data,
            fields, new int[] { R.id.field1, R.id.field2 });

そして、期待どおりに機能し始めました。

MyCursorAdapter (拡張SimpleCursorAdapter) コンストラクター:

public MyCursorAdapter(Context context, int layout, Cursor c,
        String[] from, int[] to) { //... }
于 2012-02-09T14:21:22.153 に答える