简体   繁体   中英

How can I set transparency of MediaController background in android

I want to set the transparency of MediaController background and not controls.

I tried using mediaController.setAlpha(0.6f), but it is applying transparency to controls as well like this

try setting the background color with a transparent color instead of alpha.

For example, with color hex #99CC00:

In your colors.xml :

<resources>
  <color name="NoTransparent">#FF99CC00</color>
  <color name="AlmostTransparent">#4499CC00</color>
  <color name="FullTransparent">#0099CC00</color>
</resources>

Then in your activity:

mediaController.setBackgroundColor(getResources().getColor(R.color.AlmostTransparent));

Or in your layout file:

<MediaController
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/media_controller"
    android:background="@color/AlmostTransparent" />

Found a tricky solution, that worked for me. The idea is to set background color with desired transparency level only for the specific background layout. This will not have an impact on controls or other MediaController views:

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mediaPlayer) {
                // get media controller background layout
                LinearLayout viewGroupLevel1 = (LinearLayout)  mediaController.getChildAt(0);   
                //Set your color with desired transparency here:
                viewGroupLevel1.setBackgroundColor(getResources().getColor(R.color.transparent));
            }
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM