J'essaie de diffuser mon application sur Chromecast. J'ai commencé par ajouter un bouton, en suivant le guide https://developers.google.com/cast/docs/android_sender_integrate.Pourquoi j'obtiens java.lang.IllegalArgumentException: l'arrière-plan ne peut pas être translucide: # 0 lors de l'utilisation de MediaRouteButton?
Après avoir ajouté le MediaRouteButton, je reçois:
Caused by: java.lang.IllegalArgumentException: background can not be translucent: #0
at android.support.v4.graphics.ColorUtils.calculateContrast(ColorUtils.java:93)
at android.support.v7.app.MediaRouterThemeHelper.getControllerColor(MediaRouterThemeHelper.java:88)
at android.support.v7.app.MediaRouterThemeHelper.getStyledRouterThemeId(MediaRouterThemeHelper.java:185)
at android.support.v7.app.MediaRouterThemeHelper.createThemedContext(MediaRouterThemeHelper.java:60)
at android.support.v7.app.MediaRouteButton.<init>(MediaRouteButton.java:124)
at android.support.v7.app.MediaRouteButton.<init>(MediaRouteButton.java:120)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:408)
at android.app.Activity.setContentView(Activity.java:2198)
J'ai cherché SO, et ont trouvé une autre question similaire, où un intervenant a demandé à ajouter un tag d'arrière-plan à l'entrée xml MediaRouteButton. Voici ma mise en page xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mdb_reader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/mdb_book_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.app.MediaRouteButton
android:id="@+id/media_route_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black"
android:layout_weight="1"
android:mediaRouteTypes="user"
android:visibility="gone" />
</LinearLayout>
</FrameLayout>
(j'ai deux dispositions imbriquées parce qu'il est utilisé par un programme, de toute façon je l'ai déjà essayé de déplacer plus le MediaRouteButton et il n'a pas aidé).
J'ai aussi vu quelques conseils en ce qui concerne le thème, voici mon AndroidManifest.xml
application
entrée:
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:background="@android:color/black"
android:theme="@style/AppTheme">
Vales/styles.xml
<resources>
<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<style name="Theme.CastVideosTheme" parent="AppBaseTheme">
<item name="mediaRouteTheme">@style/CustomMediaRouterTheme</item>
</style>
<style name="CustomMediaRouterTheme" parent="Theme.MediaRouter">
<item name="mediaRouteButtonStyle">@style/CustomMediaRouteButtonStyle</item>
</style>
<style name="CustomMediaRouteButtonStyle" parent="Widget.MediaRouter.Light.MediaRouteButton">
<item name="buttonTint">@color/black</item>
</style>
</resources>
valeurs v11/styles.xml
<resources>
<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
</style>
<style name="Theme.CastVideosTheme" parent="AppBaseTheme">
<item name="mediaRouteTheme">@style/CustomMediaRouterTheme</item>
</style>
<style name="CustomMediaRouterTheme" parent="Theme.MediaRouter">
<item name="mediaRouteButtonStyle">@style/CustomMediaRouteButtonStyle</item>
</style>
<style name="CustomMediaRouteButtonStyle" parent="Widget.MediaRouter.Light.MediaRouteButton">
<item name="buttonTint">@color/black</item>
</style>
</resources>
valeurs-v14
<resources>
<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
</style>
<style name="Theme.CastVideosTheme" parent="AppBaseTheme">
<item name="mediaRouteTheme">@style/CustomMediaRouterTheme</item>
</style>
<style name="CustomMediaRouterTheme" parent="Theme.MediaRouter">
<item name="mediaRouteButtonStyle">@style/CustomMediaRouteButtonStyle</item>
</style>
<style name="CustomMediaRouteButtonStyle" parent="Widget.MediaRouter.Light.MediaRouteButton">
<item name="buttonTint">@color/black</item>
</style>
</resources>
Me semble tout devrait fonctionner, mais je reçois toujours l'erreur putain. J'utilise Android 26 pour construire.
pouvez-vous me dire @ couleur/noir valeur? – Sunny
' # ff000000 ' Je peux changer pour autre chose, j'ai déjà essayé quelques trucs. –
Krystian
essayez ' # 000000 '. c'est-à-dire sans canal alpha. –
Sunny