How can I set transparency of MediaController background in android

前提是你 提交于 2019-12-06 09:28:56

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