gpt4 book ai didi

Android应用程序白屏被阻止而没有错误

转载 作者:行者123 更新时间:2023-11-29 01:20:13 26 4
gpt4 key购买 nike

我已经使用抽屉式导航菜单设置了我的 Android 应用程序,在完成所有设置之后,我的应用程序只显示一个白色的空白屏幕,而没有启动我的 LAUNCHER Activity ,也没有执行任何操作。

我知道它已经过时了,但我不知道出了什么问题,也因为我没有任何日志错误..我认为是主题的问题,我将在下面发布一些代码。

感谢您的帮助。

这是应用程序显示的内容: enter image description here

Theme.xml

 <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style name="AppTheme.CAFTracker" parent="AppTheme.Base">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowBackground" >@color/white</item>

<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/colorPrimary</item>
<item name="android:textColor">@color/colorPrimary</item>

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>


<item name="elevation">0dp</item>
</style>

<style name="ActionBarText" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textSize">20dp</item>
<item name="android:textColorPrimary">@android:color/white</item>
</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>

AndroidManifest.xml

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

<activity
android:name=".gui.activity.HomeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

ActivityDefault.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/screen_default_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/screen_default_content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:id="@+id/screenToolbar"
style="@style/toolbar"
tools:context=".ToolBar" />

</RelativeLayout>

<FrameLayout
android:id="@+id/screen_default_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FrameLayout" />

</LinearLayout>

<android.support.design.widget.NavigationView
android:id="@+id/navigationMenu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />

家庭 Activity

public class HomeActivity extends Base {


public static Intent getHomeActivity(Context context){
return new Intent(context, HomeActivity.class);
}

@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);

if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.screen_default_container, HomeFragment.newInstance(), AppConfig.FRAGMENT_HOME)
.commit();
}
}

@Override
protected int getContentView() {
return R.layout.activity_default;
}

@Override
protected int getTitleToolBar() {
return R.string.homeSectionName;
}

基础 Activity

public abstract class Base extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

@Bind(R.id.navigationMenu)
NavigationView mNavigationView;

@Bind(R.id.screen_default_drawer_layout)
DrawerLayout mDrawerLayout;

@Bind(R.id.screenToolbar)
protected Toolbar mToolBar;

@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);

setContentView(getContentView());

ButterKnife.bind(this);

CAFTrackerApplication.get(getApplicationContext()).inject(this);
}

@Override
protected void onStart() {
super.onStart();

if (mNavigationView != null) {
mNavigationView.setNavigationItemSelectedListener(this);

for (int menuItemPos = 0; menuItemPos < mNavigationView.getMenu().size(); menuItemPos++) {
if (mNavigationView.getMenu().getItem(menuItemPos).getItemId()
== Prefs.getIntPreference(getApplicationContext(), R.string.pref_ui_menu_selected)) {

mNavigationView.getMenu().getItem(menuItemPos).setChecked(true);
break;
}
}
}

loadInfoToolbar();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (mDrawerLayout != null) {
mDrawerLayout.openDrawer(GravityCompat.START);
}
return true;
}
return super.onOptionsItemSelected(item);
}

public void loadInfoToolbar() {
setSupportActionBar(mToolBar);

try {
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setShowHideAnimationEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
getSupportActionBar().setTitle(getTitleToolBar());

}
} catch (NullPointerException e) {
Logger.e("Support action bar is null");
}
}

@Override
protected void onDestroy() {
super.onDestroy();
ButterKnife.unbind(this);
}

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {

Logger.i("Position clicked [ " + menuItem.getItemId() + " ]");

Prefs.savePreference(getApplicationContext(), R.string.pref_ui_menu_selected, menuItem.getItemId());

//Closing drawer on item click
if (mDrawerLayout != null) {
mDrawerLayout.closeDrawers();
}

switch (menuItem.getItemId()) {
// Sub Sections
case R.id.nav_home:
startActivity(HomeActivity.getHomeActivity(getApplicationContext()));
return true;
}

return false;
}


protected abstract int getContentView();

protected abstract int getTitleToolBar();
}

最佳答案

改变

    @Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);

if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.screen_default_container, HomeFragment.newInstance(), AppConfig.FRAGMENT_HOME)
.commit();
}
}

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

if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.screen_default_container, HomeFragment.newInstance(), AppConfig.FRAGMENT_HOME)
.commit();
}
}

关于Android应用程序白屏被阻止而没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37279841/

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