How can I set transparency of MediaController back

2020-07-27 03:36发布

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

2条回答
欢心
2楼-- · 2020-07-27 03:46

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" />
查看更多
Luminary・发光体
3楼-- · 2020-07-27 04:07

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));
            }
        });
查看更多
登录 后发表回答