Created
July 7, 2021 12:40
-
-
Save AkaashSaini/2f6bea7117c08a4b1137b3e50047776c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
activity_main.xml | |
<TextView | |
android:id="@+id/textView" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Click the button to go to pip mode!" | |
android:textColor="@color/black" | |
android:textSize="20dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:layout_constraintVertical_bias="0.454" /> | |
<Button | |
android:id="@+id/button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Go pip mode" | |
android:onClick="goPip" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintHorizontal_bias="0.498" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/textView" | |
app:layout_constraintVertical_bias="0.061" /> | |
->in Manifest.xml | |
<activity android:name=".MainActivity" | |
android:resizeableActivity="true" | |
android:supportsPictureInPicture="true" | |
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" | |
> | |
->MainActivity.java | |
public class MainActivity extends AppCompatActivity { | |
TextView textView; | |
Button button; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
textView=findViewById(R.id.textView); | |
button=findViewById(R.id.button); | |
} | |
public void goPip(View view) { | |
enterPictureInPictureMode(); | |
} | |
@Override | |
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) { | |
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); | |
if (isInPictureInPictureMode){ | |
getSupportActionBar().hide(); | |
textView.setText("INSIDE PIP"); | |
button.setVisibility(View.INVISIBLE); | |
} | |
else{ | |
getSupportActionBar().show(); | |
textView.setText("Click the button to go to pip mode!"); | |
button.setVisibility(View.VISIBLE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment