Android应用白屏被阻止且没有错误

时间:2016-05-17 15:04:43

标签: android android-toolbar android-theme android-styles blocked

我已经使用抽屉导航菜单设置了我的Android应用程序,在完成所有设置后,我的应用程序只是显示一个白色的空白屏幕而没有启动我的启动器活动而且什么也没做。

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

感谢您的帮助。

这是应用显示的内容: 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" />

家庭活动

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;
}

}

BaseActivity

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();
}

1 个答案:

答案 0 :(得分:1)

更改

    @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();
    }
}