android mediacontroller - defining the mediacontroller in the layout xml

丶灬走出姿态 提交于 2020-01-04 06:55:21

问题


In the android documentation on the MediaController widget I read

Functions like show() and hide() have no effect when MediaController is created in an xml layout.

which points to the fact the the mediacontroller can be defined in the xml layout. As I want a controller which never hides and also doesn't take the focus so that it is possible to click buttons on the rest of the screen I tried to go the xml layout way. As I can't get this to work I am looking for an example on how to use MediaController by defining it in the layout xml.

Any hint highly appreciated


回答1:


I found one workaround for Android 2.x. Sadly it doesn't seem to work in 4.x.

You need to call setAnchorView() to show the MediaController. This code worked for me in Android 2.2 and 2.3.6, but caused crash in 4.0.4:

mediaController.setAnchorView(mediaController);

I also tried passing activity content view to setAnchorView(), but it still crashing in 4.0.4.

The most reliable way is to instantiate it programatically as said in documentation:

The way to use this class is to instantiate it programatically.



来源:https://stackoverflow.com/questions/12875232/android-mediacontroller-defining-the-mediacontroller-in-the-layout-xml

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