2016-04-28 21 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