成功勾选:Java - Android 9 (Pie) - Android Studio 4.1.3 - 华为P10
六个月来,我无法解决这个需求。问题出在代码中未分配的标志“FLAG_FULLSCREEN”中。
第一步MainActivity.java:
public class MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // If the animation still is, try applying it.
setRotationAnimation();
}
private void setRotationAnimation() {
int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.rotationAnimation = rotationAnimation;
win.setAttributes(winParams);
}
public void Button (View view) {
// Connected to android:onClick="Button" in XML.
Intent intent = new Intent(MainActivity.this, MainActivity2.class);
startActivity(intent);
}
}
下一步MainActivity2.java:
public class MainActivity2 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
/* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // If the animation still is, try applying it.
setRotationAnimation();
}
private void setRotationAnimation() {
int rotationAnimation =
WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.rotationAnimation = rotationAnimation;
win.setAttributes(winParams);
}
public void Button (View view) {
Intent intent = new Intent(MainActivity2.this, MainActivity.class);
startActivity(intent);
}
}
下一步styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowFullscreen">true</item>
</style>
</resources>
我理解的简单事情:您必须首先在任何地方启动“setRotationAnimation()”,然后再运行 activity2。启动 activity2 时,您必须在其中运行“setRotationAnimation()”。工作不正确。