我有一个 ListView 和一个仅由 TextView 和 Button 组成的自定义项布局。实际的 ListView 工作正常,但在我测试的不同设备上显示不同。
在我的 Android 8.0 设备上,文本是深灰色的,但在我的 6.0 设备上,文本是浅灰色的,在我的 Activity 的白色背景下几乎看不到。此外,该设备上的按钮颜色也颠倒了,在 8.0 中浅色按钮上显示深色文本,而在 6.0 中则相反。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cell_peer"
android:descendantFocusability="blocksDescendants"
android:padding="3dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/text_peer_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="TextView"
tools:text="@tools:sample/full_names" />
<Button
android:id="@+id/button_call_peer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Call"
app:layout_constraintEnd_toEndOf="parent"
/>
</RelativeLayout>
list :
<activity android:name=".activities.FriendsListActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="Call a friend"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
></activity>
我可以通过在 TextView 上设置 android:textColor="@color/color_callable_peer_name"
来轻松解决文本对比度问题,但我的问题是:为什么此文本默认为不同的颜色平台?
最佳答案
因为您可以轻松做到这一点。
public class MyTextView extends TextView {
public MyTextView (Context context) {
super(context);
if (android.os.Build.VERSION.SDK_INT == ......Marshmallow){
// set text color you wanted}
else
{
//set text color you wanted
}
}
}
在您的 xml 文件中使用 MyTextView 而不是 TextView。
关于android - 复杂 ListView 项目中的 TextView 文本颜色因设备而异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55091411/