2017-01-02 62 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

相關問題