Mic*_*odd 4 android android-listview android-theme
我目前在使用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>
Run Code Online (Sandbox Code Playgroud)
注意:我目前不得不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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我目前没有使用任何自定义样式.感谢阅读,任何有用的评论将不胜感激.
编辑1:
这是请求的截图.
如果我没有指定文本颜色,它就是它的外观,似乎是使用Holo Dark的默认文本颜色
手动指定android:textColor="?android:attr/textColorPrimaryInverse"给出了这个结果,但我很难使用这样的解决方法.
小智 22
你还没有发布任何实际的代码,但由于我遇到了完全相同的问题,我猜你错Context了你的自定义适配器构造函数.
我一直在做这样的事情(在我的片段中):
dataSource = new MyCursorAdapter(getActivity().getApplicationContext(), R.layout.myrow, data,
fields, new int[] { R.id.field1, R.id.field2 });
Run Code Online (Sandbox Code Playgroud)
我必须做的就是解决问题,取而代之的getActivity().getApplicationContext()是getActivity():
dataSource = new MyCursorAdapter(getActivity(), R.layout.myrow, data,
fields, new int[] { R.id.field1, R.id.field2 });
Run Code Online (Sandbox Code Playgroud)
它开始按预期工作.
MyCursorAdapter(扩展SimpleCursorAdapter)构造函数:
public MyCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) { //... }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4616 次 |
| 最近记录: |