gpt4 book ai didi

android - 应用程序从 SplashScreenActivity(全屏)移动到 MainActivity(非全屏)时出现

转载 作者:太空狗 更新时间:2023-10-29 14:51:47 25 4
gpt4 key购买 nike

我有一个全屏的 SplashScreenActivity,它会在 3 秒后移动到 MainActivity

styles.xml 用于 SplashScreenActivity :

<!-- 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>
MainActivity

styles.xml:

<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="vpiCirclePageIndicatorStyle">@style/CustomCirclePageIndicator</item>
</style>

当应用程序从SplashScreenActivity移动到MainActivity时,因为它从全屏移动到非全屏,Layout出现然后移动有点向下。

我已经用过了

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

还有

android:paddingTop="25dp"

但运气不好。

谁能解决这个问题??

编辑:

SplashScreenActivity:

    public class SplashScreenActivity extends AppCompatActivity {

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

setContentView(R.layout.splash);
EventBus.getDefault().register(this);
callWeatherService(this);
delayedTask();
}

private void delayedTask() {
Runnable splashRunnable = new Runnable() {
@Override
public void run() {
startActivity(new Intent(this, MainActivity.class));
}
};
new Handler().postDelayed(splashRunnable, Numerics.THREE_THOUSAND);
}

public void onEventMainThread(WeatherModel weather) {
if (weather != null) {
Preferences.getIns().saveWeather(weather);
}
}

@Override
public void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
}

主 Activity :

    public class MainActivity extends AppCompatActivity implements ExpandableListView.OnGroupClickListener, ExpandableListView.OnChildClickListener, ExpandableListView.OnGroupExpandListener, View.OnClickListener {

private Toolbar mToolbar;

private DrawerLayout mDrawerLayout;

private FragmentManager mFragmentManager;

private FragmentTransaction mFragmentTransaction;

private ExpandableListAdapter mExpandableListAdapter;

private ExpandableListView mExpandableListView;

private List<String> mGroupList;

private Map<String, List<String>> mChildList;

private TextView toolbarTitle;

private ImageView weatherImg;

private int selectedItem = -1;

private int lastExpandedPosition = -1;

private TextView userEmailTxt;

private TextView userNameTxt;

private ImageView editBtn;

public int getSelectedItem() {
return selectedItem;
}

public void setSelectedItem(int selectedItem) {
this.selectedItem = selectedItem;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
setContentView(R.layout.activity_main);

mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbarTitle = (TextView) findViewById(R.id.toolbar_title);
weatherImg = (ImageView) findViewById(R.id.weather_img);
weatherImg.setOnClickListener(this);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(
this, mDrawerLayout, mToolbar,
R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
if (lastExpandedPosition != -1
) {
mExpandableListView.collapseGroup(lastExpandedPosition);
}
lastExpandedPosition = -1;
}
};

mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerToggle.syncState();

setDrawerList();
setUserDetails();
setFonts();
loadFragment(0);

}

private void setUserDetails() {
userNameTxt = (TextView) findViewById(R.id.user_name);
userEmailTxt = (TextView) findViewById(R.id.user_email);
editBtn = (ImageView) findViewById(R.id.edit_btn);
editBtn.setOnClickListener(this);
userNameTxt.setText(R.string.lokes);
userEmailTxt.setText(R.string.lokesh_mail);

}

private void setDrawerList() {
mExpandableListView = (ExpandableListView) findViewById(R.id.expandable_lst);
mExpandableListView.setGroupIndicator(null);

prepareListData();

mExpandableListAdapter = new ExpandableListAdapter(this, mGroupList, mChildList);

// setting list adapter
mExpandableListView.setAdapter(mExpandableListAdapter);
mExpandableListView.setOnGroupClickListener(this);
mExpandableListView.setOnChildClickListener(this);
mExpandableListView.setOnGroupExpandListener(this);
}

private void prepareListData() {
// data to expandable list view
}

private void loadFragment(int position) {
String title = null;
invalidateOptionsMenu();
Fragment fragment = null;
if (position == getSelectedItem()) {
// Already selected fragment is being displayed
} else {
switch (position) {
case Numerics.ZERO:
fragment = new DashBoardFragment();
title = getString(R.string.dashboard);
break;
case Numerics.ONE:
break;
case Numerics.TWO:
break;
case Numerics.THREE:
break;
case Numerics.FOUR:
break;
case Numerics.FIVE:
break;
default:
break;
}
if (fragment != null) {
showFragment(fragment, title);
}
setSelectedItem(position);
}
}

public void showFragment(Fragment fragment, String title) {
if (fragment != null) {
String backStateName = fragment.getClass().getName();
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.dashboard_container, fragment);
mFragmentTransaction.addToBackStack(backStateName);
mFragmentTransaction.commit();
setActionBarTitle(title);
if (backStateName == DashBoardFragment.class.getSimpleName()) {
clearBackStack();
}
}
}

public void setActionBarTitle(String title) {
if (toolbarTitle != null && !TextUtils.isEmpty(title)) {
toolbarTitle.setText(title);
}
}

private void clearBackStack() {
mFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
setSelectedItem(Numerics.ZERO);
}

@Override
public void onBackPressed() {
if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.closeDrawers();
} else {
int backStackCount = mFragmentManager.getBackStackEntryCount();
if (backStackCount > 0) {
popFragments(backStackCount);
} else {
finish();
}
}
}

private void popFragments(int backStackCount) {
String fragmentTag = mFragmentManager.getBackStackEntryAt(
backStackCount - 1).getName();
if (!TextUtils.isEmpty(fragmentTag)) {
Fragment currentFragment = mFragmentManager
.findFragmentById(R.id.dashboard_container);
if (currentFragment != null && currentFragment instanceof DashBoardFragment) {
finish();
} else {
mFragmentManager.popBackStack();
}
}
}

@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
if (mChildList.get(mGroupList.get(groupPosition))
.isEmpty() && mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.closeDrawer(Gravity.LEFT);
}
return false;
}

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
v.setBackgroundResource(R.color.exp_lst_selected);
if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.closeDrawer(Gravity.LEFT);
}
openChild(groupPosition, childPosition);
return false;
}

private void openChild(int groupPosition, int childPosition) {
//handle on open child
}

@Override
public void onGroupExpand(int groupPosition) {
if (lastExpandedPosition != -1
&& groupPosition != lastExpandedPosition) {
mExpandableListView.collapseGroup(lastExpandedPosition);
}
lastExpandedPosition = groupPosition;
}

private void setFonts() {
Fonts.getInstance(this).setMediumFont(toolbarTitle);
}

@Override
public void onClick(View v) {
ToastFactory.showToast(R.string.app_name);
}
}

编辑 2:

AndroidManifest.xml :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />

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

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

<activity android:name=".activities.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>

<service android:name=".services.rest.RestService" />
</application>

最佳答案

你有太多什么都不做的行。这是我的示例,它按预期工作:在 list 中什么都不做:

 <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name" />
</application>

在我的 styles.xml 中什么都不做,只是从正确的主题扩展

 <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
//nothing to do with fullscreen it all extended
</style>

Splash Activity 只是 LinearLayout 。主 Activity 根本没有覆盖窗口,您已经扩展了正确的主题。

public class MainActivity extends AppCompatActivity {

private DrawerLayout mDrawerLayout;
private Toolbar toolbar;
private ActionBarDrawerToggle mDrawerToggle;

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

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
toolbar = (Toolbar) findViewById(R.id.main_page_toolbar_parent);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle(null);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.action_settings, R.string.app_name) {

/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportFragmentManager().beginTransaction().replace(R.id.container_frame, new MainActivityFragment()).commit();
}
}

它适用于我需要 Splash 的所有应用程序。

关于android - 应用程序从 SplashScreenActivity(全屏)移动到 MainActivity(非全屏)时出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34653912/

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