我决定将Night Theme添加到我的应用中,因此我将@colors
替换为?attrs
。
所以我有一个activity
toolbar
,我正试图用一些设置打开一个对话框。对话框不希望打开并导致崩溃。
日志:
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 class android.widget.TextView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:424)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:415)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:204)
at android.widget.Spinner.onMeasure(Spinner.java:602)
at android.support.v7.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:426)
at android.view.View.measure(View.java:23165)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:23165)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23165)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:23165)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23165)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23165)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:720)
at android.view.View.measure(View.java:23165)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2689)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1528)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1826)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1443)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7125)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:935)
at android.view.Choreographer.doCallbacks(Choreographer.java:747)
at android.view.Choreographer.doFrame(Choreographer.java:682)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:921)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f0401a5 a=-1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:546)
at android.widget.TextView.readTextAppearance(TextView.java:3542)
at android.widget.TextView.<init>(TextView.java:959)
at android.widget.TextView.<init>(TextView.java:869)
at android.widget.TextView.<init>(TextView.java:865)
... 52 more
这是它不喜欢的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/vk_white"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="@+id/headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/setup_home"
android:textSize="20sp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/headline"
android:background="?attr/vk_grey_color"/>
<LinearLayout
android:orientation="vertical"
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/headline">
<RelativeLayout
android:id="@+id/warning_layout"
android:layout_width="match_parent"
android:visibility="gone"
android:background="?attr/warning"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/warning_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_warning"
android:padding="10dp"/>
<TextView
android:layout_toRightOf="@id/warning_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/vk_white"
android:textSize="16sp"
android:text="@string/warning_home"
android:padding="8dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp">
<TextView
android:id="@+id/whose_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/show_photos_of"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<Spinner
android:id="@+id/whose_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginBottom="15dp"
android:layout_below="@+id/whose_show"
android:layout_alignParentRight="true"
/>
<RelativeLayout
android:id="@+id/edit_layout"
android:layout_width="match_parent"
android:layout_below="@+id/whose_spinner"
android:visibility="gone"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:padding="10dp"
android:text="@string/how_many"/>
<EditText
android:id="@+id/counter_edit"
android:layout_alignParentRight="true"
android:layout_width="60dp"
android:gravity="center"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
</RelativeLayout>
<Button
android:id="@+id/setup_button"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:padding="3dp"
android:layout_below="@+id/whose_spinner"
android:layout_centerHorizontal="true"
android:text="@string/setup_list" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/sort_by_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:layout_marginBottom="5dp">
<TextView
android:id="@+id/sorttext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/sort" />
<Spinner
android:layout_below="@id/sorttext"
android:id="@+id/sort_spinner"
android:layout_marginLeft="3dp"
android:paddingBottom="3dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
<View
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/sort_by_name"
android:background="?attr/vk_grey_color"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/savePrefsHome"
android:layout_alignParentEnd="true"
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:background="@android:color/transparent"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.Button.Borderless.Colored" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
我已经尝试从@style
删除TextViews
个部分,但它没有帮助。有没有人遇到类似的问题?有什么问题?
修改
对话框启动如下:
HomeDialog settings = new HomeDialog();
settings.showDialog(activity, getWhoseSelected(), getSortSelected());
showDialog方法只是将这些数据用于spiners的设置。 这里也是样式XML:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#3e4160</item>
<item name="colorPrimaryDark">#203e58</item>
<item name="colorAccent">#5f6cde</item>
<item name="homepage">#f4f4f4</item>
<item name="home">#e4e4e4</item>
<item name="darkgrey">#b4b4b4</item>
<item name="lighty">#fcfcfc</item>
<item name="darkest">#5e5e5e</item>
<item name="warning">#a8b2d4</item>
<item name="notification">#b8abd4</item>
<item name="pano">#1f4490</item>
<item name="pinky">#ff6b6b</item>
<item name="navColor">#203e58</item>
<item name="vk_black">#000</item>
<item name="vk_grey_color">#f0f2f5</item>
<item name="vk_white">#fff</item>
<item name="black_overlay">#66000000</item>
</style>
<!-- Dark application theme. -->
<style name="AppTheme_NightMode" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#252525</item>
<item name="colorPrimaryDark">#161616</item>
<item name="colorAccent">#5f6cde</item>
<item name="homepage">#252525</item>
<item name="home">#3b3b3b</item>
<item name="darkgrey">#b4b4b4</item>
<item name="lighty">#fcfcfc</item>
<item name="darkest">#5e5e5e</item>
<item name="warning">#a8b2d4</item>
<item name="notification">#b8abd4</item>
<item name="pano">#1f4490</item>
<item name="pinky">#ff6b6b</item>
<item name="navColor">#9e9e9e</item>
<item name="vk_black">#000</item>
<item name="vk_grey_color">#f0f2f5</item>
<item name="vk_white">#fff</item>
<item name="black_overlay">#66000000</item>
</style>
Dialog正在HomeDialog类中构建:
final Dialog dialog = new Dialog(activity);
// some actions with the data
dialog.show();