我有一个MenuActivity,在MenuActivity我有一个SeguridadMenuFrament,在SeguridadMenuFrament我有SeguridadFragment。在SeguridadFrament我需要的工具YoutubePlayer。
在我的 fragment_seguridad.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/TR_CARACTERISTICAS"
android:textSize="@dimen/text_14"
android:layout_marginTop="20dp"/>
<TextView
android:id="@+id/tvCaracteristicas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/text_12"
app:layout_constraintTop_toBottomOf="@id/tvTitle"
android:layout_marginTop="20dp"/>
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="@+id/youtubePF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/tvCaracteristicas"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
在SeguridadFragment.java中
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_seguridad, container, false);
mYoutubePlayerFragment = new YouTubePlayerSupportFragment();
mYoutubePlayerFragment.initialize(YoutubeDeveloperKey, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
if (!b) {
youTubePlayer.cueVideo("NMwE93GQcKs"); …Run Code Online (Sandbox Code Playgroud)