Although your answer has already been given.
Incase You still have problems with the code, you can use this full code (both java and xml).
YoutubeActivity.java
public class YoutubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener { private static final int RECOVERY_REQUEST = 1; private YouTubePlayerView youTubeView; private YouTubePlayer youTubePlayer; public static final String YOUTUBE_API_KEY = "YOUR-API-KEY"; private String youtubeid; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_youtube); youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_player); youTubeView.initialize(YOUTUBE_API_KEY, this); Bundle extras = getIntent().getExtras(); if (extras != null) { youtubeid = extras.getString("youtubeid"); } } @Override public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) { if (!wasRestored) { YouTubePlayer.PlayerStyle style = YouTubePlayer.PlayerStyle.DEFAULT; player.setPlayerStyle(style); player.setFullscreen(true); player.setShowFullscreenButton(false);
activity_youtube.xml // your xml file layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#000000"> <com.google.android.youtube.player.YouTubePlayerView android:id="@+id/youtube_player" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout>
source share