2016-04-28 31 views
-1

我想剪裁我的微调主题属性。 这里是我的飞旋项目布局与主题的Android自定义微调框架

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@style/DashboardSpinnerItemStyle" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ellipsize="marquee" 
    android:singleLine="true" 
    android:text="test" 
    android:textSize="@dimen/material_text_body1" /> 

我使用自定义样式

<style name="DashboardSpinnerItemStyle" parent="Widget.AppCompat.TextView.SpinnerItem"> 
    <item name="android:textColor">?dashboard_color</item> 
    <item name="android:background">#00F</item> 
</style> 

有属性颜色至极我的主题

<style name="WhiteDashboardTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="android:textColor">@android:color/white</item> 
    <item name="dashboard_shape">@drawable/dashboard_center_shape_white</item> 
    <item name="dashboard_color">@android:color/white</item> 
    <item name="spinner_background">@drawable/dashboard_spinner_white</item> 
    <item name="dashboard_spinner_item_style">@style/DashboardSpinnerItemStyle</item> 
</style> 

enter image description here

工作得很好确定,但模拟器或真实设备会抛出异常

04-28 09:01:44.909 2460-2460/com.amocrm.prototype E/AndroidRuntime: FATAL EXCEPTION: main android.view.InflateException: Binary XML file line #2: Error inflating class TextView

我该怎么办了?

回答

0

你可以试试下面的代码

// Initializing an ArrayAdapter 
    final ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
      this,R.layout.spinner_item,plantsList){ 
     @Override 
     public View getDropDownView(int position, View convertView, 
            ViewGroup parent) { 
      View view = super.getDropDownView(position, convertView, parent); 
      TextView tv = (TextView) view; 

       // Set the Text color 
       tv.setTextColor(Color.parseColor("#FFC9A3FF")); 

      return view; 
     } 
    }; 
    spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_item); 
    spinner.setAdapter(spinnerArrayAdapter); 
+1

当然我可以自定义我的看法了适配器,但我想这样做了XML。问题是为什么在AndroidStudio预览中everyting正常工作?但在真实的设备上它崩溃了。 –

+0

Android预览只需简单地使用UI即可。从android预览你不能通过例外判断你的应用程序。它只是为了设计 – sukhbir