2017-01-02 121 views
-2

我创建了一个应用程序,其中主活动获得白色屏幕。
我没有得到它...
每当我启动我的应用程序它只显示一个白色的屏幕,没有别的。我的主要活动在启动时获得白色屏幕

我很困惑,请大家帮忙

这里是我的代码

主要活动

package com.example.admin.pcremote; 

import android.content.Context; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.content.res.Resources; 
import android.os.Bundle; 
import android.support.v7.app.AlertDialog; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.support.design.widget.NavigationView; 
import android.support.v4.view.GravityCompat; 
import android.support.v4.widget.DrawerLayout; 
import android.support.v7.app.ActionBarDrawerToggle; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.Toast; 

public class MainActivity extends AppCompatActivity 
    implements NavigationView.OnNavigationItemSelectedListener { 
ListView list; 
String[] menutitles; 
String[] menudescriptions; 
int images[]={R.drawable.mouse,R.drawable.keyboard,R.drawable.filemanager,R.drawable.media,R.drawable.power}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    Resources res = getResources(); 
    menutitles=res.getStringArray(R.array.titles); 
    menudescriptions=res.getStringArray(R.array.descriptions); 
    list = (ListView) findViewById(R.id.listView); 
    listadapter adptr=new listadapter(this,menutitles,images,menudescriptions); 
    list.setAdapter(adptr); 
    onclick(); 
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
    drawer.setDrawerListener(toggle); 
    toggle.syncState(); 

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
    navigationView.setNavigationItemSelectedListener(this); 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     Toast.makeText(MainActivity.this, "Setting", Toast.LENGTH_LONG).show(); 
     return true; 
    }else if (id == R.id.exit) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 
      builder.setMessage("Do You Want To Exit?").setCancelable(false) 
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          finish(); 
         } 
        }).setNegativeButton("No", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 
       } 
      }); 
      AlertDialog alert = builder.create(); 
      alert.setTitle("Exit!!"); 
      alert.show(); 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

@SuppressWarnings("StatementWithEmptyBody") 
@Override 
public boolean onNavigationItemSelected(MenuItem item) { 
    // Handle navigation view item clicks here. 
    int id = item.getItemId(); 
} 

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    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" > 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</android.support.design.widget.NavigationView> 

</android.support.v4.widget.DrawerLayout> 
+2

必须有人校对一个的冠军。 。 – Clive

+0

请添加列表代码 –

+0

可能重复的[屏幕变得白色之前在Android的飞溅](http://stackoverflow.com/questions/36966080/screen-goes-white-before-splash-in-android) –

回答

0

我也有同样的问题,试试这个。它为我工作。

改变content_main.xml德兴视图从AppTheme.NoActionBarAppTheme

in design view

enter image description here

+0

我没有得到它在哪里做到这一点:( – user7364932

+0

你会得到双击文件,在底部你会得到设计视图和文本视图 –

+0

哦谢谢它作品:) – user7364932

0

你忘了这里包含内容页!

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 
<!--Main Content Goes Here--> 
<include layout="@layout/content_home_page" /> 
<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    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" > 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</android.support.design.widget.NavigationView> 

</android.support.v4.widget.DrawerLayout> 
+0

我已经减少了代码,然后张贴在这里 – user7364932

+0

你是否在activity_main布局中包含内容?如果不是那样就像我提到 –

+0

谢谢我得到了解决方案 – user7364932

相关问题