我为android attrs.xml文件添加了一个属性,用于不同的颜色深浅.在styles.xml文件中,我给出了这些属性颜色,因此它们对于每种样式都是不同的.
Attrs.xml:
<attr name="lightBackground" format="color" />
<attr name="normalBackground" format="color" />
Run Code Online (Sandbox Code Playgroud)
styles.xml:
<style name="AppThemeNight" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimaryNight</item>
<item name="colorPrimaryDark">@color/colorPrimaryDarkNight</item>
<item name="colorAccent">@color/colorAccentNight</item>
<item name="drawerArrowStyle">@style/DrawerIcon</item>
<item name="lightBackground">@color/colorPrimaryLightNight</item>
<item name="normalBackground">@color/colorPrimaryNight</item>
</style>
Run Code Online (Sandbox Code Playgroud)
膨胀自定义微调器布局:spinner_layout_adapter.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerLayoutAdapter_tv_spinnerText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="15dp"
android:text="TextView"
android:textColor="@android:color/white"
android:background="?attr/normalBackground"
android:textSize="16sp"/>
Run Code Online (Sandbox Code Playgroud)
然而,
05-23 14:22:34.833 17231-17231/nl.gemeente.breda.bredaapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: nl.gemeente.breda.bredaapp, PID: 17231
android.view.InflateException: Binary XML file line #3: Binary XML file line #3: Error inflating class android.widget.TextView
Caused by: android.view.InflateException: Binary XML file line #3: Error inflating …Run Code Online (Sandbox Code Playgroud)