2013-10-07 64 views
3

我有一些奇怪的問題:添加MediaRouteButton後,我的應用程序崩潰

我加入了MediaRouteButton在我的佈局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/group_right" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_alignParentRight="true" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/right_btns" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:minWidth="@dimen/actionbar_icon_width" 
     android:orientation="horizontal" > 
    </LinearLayout> 

    <android.support.v7.app.MediaRouteButton 
     android:id="@+id/media_route_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

它的作品真的罰款我的新設備。但對於3.1,2.3或更低較舊的設備我得到這個例外

Caused by: android.view.InflateException: Binary XML file line #74: Error inflating class android.support.v7.app.MediaRouteButton 
at android.view.LayoutInflater.createView(LayoutInflater.java:596) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:671) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:724) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:727) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:479) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:391) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:347) 
at de.myapp.views.MyActionBar.<init>(MyActionBar.java:54) 
... 36 more 
Caused by: java.lang.reflect.InvocationTargetException 
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:416) 
at android.view.LayoutInflater.createView(LayoutInflater.java:576) 
... 43 more 
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01000c a=3} 
at android.content.res.Resources.loadDrawable(Resources.java:1841) 
at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 
at android.view.View.<init>(View.java:2462) 
at android.support.v7.app.MediaRouteButton.<init>(MediaRouteButton.java:121) 
at android.support.v7.app.MediaRouteButton.<init>(MediaRouteButton.java:117)  
... 46 more 

在我的代碼,當我吹大XML佈局

public MyActionBar(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     inflate(context, R.layout.group_action_bar, this); 
     titleGroup = (ViewGroup) findViewById(R.id.group_title); 
     leftBtnGroup = (ViewGroup) findViewById(R.id.left_btns); 
     rightBtnGroup = (ViewGroup) findViewById(R.id.right_btns); 
     titleAppendix = findViewById(R.id.group_title_appendix); 
    } 

有誰知道爲什麼這不起作用它發生對於api級別較低的舊設備?

謝謝!

回答

13

我能解決它自己

問題是繪製/ list_selector_background.xml

在預ICS設備的選擇有不同的實現。我無法訪問support-v7-lib的代碼。但設置MediaRouteButton透明的背景爲我解決。

<android.support.v7.app.MediaRouteButton 
    android:id="@+id/media_route_button" 
    android:layout_width="wrap_content" 
    android:background="@android:color/transparent" 
    android:layout_height="wrap_content"/> 
+0

有在最新的支持庫(23.1.1)中的錯誤,這將不再有效:https://code.google.com/p/android/issues/detail?id=192960&colspec=ID% 20Type%20Status%20Owner%20Summary%20Stars –

相關問題