gpt4 book ai didi

android - 从全屏 Activity 移动到非全屏 Activity 时,工具栏和状态栏发生碰撞

转载 作者:行者123 更新时间:2023-11-30 01:31:49 25 4
gpt4 key购买 nike

您好,请看附件视频了解问题

Video

SplashScreenActivity

    public class SplashScreenActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.splash);

findViewById(R.id.txt_skip).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
}
});
}

}

主要 Activity

    public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

样式

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<!-- Theme for Splash with no Action bar full screen -->
<style name="splash_screen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>

样式/v21

<?xml version="1.0" encoding="utf-8"?>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
</style>

list

<?xml version="1.0" encoding="utf-8"?>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".SplashScreenActivity"
android:theme="@style/splash_screen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />

</application>

activity_main:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


<TextView
android:id="@+id/toolbar_title"
style="@android:style/TextAppearance.Large"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Demo App"
android:textColor="@android:color/white" />

</android.support.v7.widget.Toolbar>

谁能帮我解决这个问题??

最佳答案

我试过你的代码,发现当 MainActivitySplashActivity 中点击跳过按钮后打开时,系统开始绘制状态栏但不是立即,因为它正在打开一些动画,直到 MainActivity 布局让整个屏幕 Canvas 自行绘制。在尝试修复主题或样式几分钟后,我没有成功,我想出了一个 hack,显示状态在开始 MainActivity 之前设置栏,这样 MainActivity 的布局就不会获得全屏 Canvas 来绘制自身。

您也可以试试这个 hack。

public class SplashScreenActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.splash);

findViewById(R.id.txt_skip).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT > 16) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
getWindow().getDecorView().decorView.setSystemUiVisibility(uiOptions);
}
startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
}
});
}
}

希望对您有所帮助。让我知道这是否解决了您的问题?

关于android - 从全屏 Activity 移动到非全屏 Activity 时,工具栏和状态栏发生碰撞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35645865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com