问题
I've added the android-support-v7-appcompat,android-support-v7-mediarouter library project to build path.
following are my main activity and no errors for import the button, but when execute the app, error inflating MediaRouteButton happens. Thanks a lot for any advice!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<android.support.v7.app.MediaRouteButton
android:id="@+id/castbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
>
</android.support.v7.app.MediaRouteButton>'
...
public class MainActivity extends android.support.v4.app.FragmentActivity
implements OnClickListener {
private android.support.v7.app.MediaRouteButton castbutton;
回答1:
First of all you should replace this
<android.support.v7.app.`MediaRouteButton`
android:id="@+id/castbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
>
</android.support.v7.app.MediaRouteButton>
With
<android.support.v7.app.MediaRouteButton
android:id="@+id/castbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
>
</android.support.v7.app.MediaRouteButton>
Update: You must appcompat referecning
first. To add appcompat library into your Follow the steps Right Click Project--> go to properties--> android ---> ib tab
to add the appcompat project.
来源:https://stackoverflow.com/questions/21965402/error-inflating-class-android-support-v7-app-mediaroutebutton