1、错误说明
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.styleandroidusing/com.example.styleandroidusing.StyleAndroidUsingMainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
2、解决方法
错误地址:
android:textSize="@style/mandatory_text_field_style"
纠正代码:
3、代码共享
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@color/background_color"
android:orientation="vertical" >
<TextView
android:id="@+id/TextView01"
style="@style/mandatory_text_field_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mand_label" />
<EditText
android:id="@+id/editText1"
style="@style/mandatory_text_field_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="@string/mand_feault" />
<TextView
android:id="@+id/textView1"
style="@style/optional_text_field_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/opt_label" />
<EditText
android:id="@+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="@string/opt_default" />
<TextView
android:id="@+id/TextView02"
style="@style/optional_text_field_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/opt_label" />
<EditText
android:id="@+id/EditText02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="@string/opt_default" />
</LinearLayout>
<style name="AppTheme" parent="android:Theme.Light" />
<style name="mandatory_text_field_style">
<item name="android:textColor">#000000</item>
<item name="android:textSize">14pt</item>
<item name="android:textStyle">bold</item>
</style>
<style name="optional_text_field_style">
<item name="android:textColor">#0F0F0F</item>
<item name="android:textSize">12pt</item>
<item name="android:textStyle">italic</item>
</style>
</resources>