How can I set transparency of MediaController background in android

核能气质少年 提交于 2019-12-12 09:59:29

问题


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


回答1:


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" />



回答2:


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));
            }
        });


来源:https://stackoverflow.com/questions/38359958/how-can-i-set-transparency-of-mediacontroller-background-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!