2017-10-17 31 views
-3

運行這是我的代碼:MainActivity後無法splashcreen

package pi.com.pariwisata; 

import android.app.AlertDialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.os.Bundle; 
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.MenuItem; 

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     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 void onBackPressed() { 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     if (drawer.isDrawerOpen(GravityCompat.START)) { 
      drawer.closeDrawer(GravityCompat.START); 
     } else { 
      super.onBackPressed(); 
     } 
    } 


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

     if (id == R.id.nav_maps) { 
      Intent peta = new Intent(this, MapsActivity.class); 
      startActivity(peta); 
     } else if (id == R.id.nav_list) { 
      Intent list = new Intent(this, ListActivity.class); 
      startActivity(list); 
     } else if (id == R.id.nav_about) { 
      Intent tentang = new Intent(this, TentangActivity.class); 
      startActivity(tentang); 
     } else if (id == R.id.nav_exit) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(this); 
      builder.setMessage("Keluar Dari Aplikasi?") 
        .setCancelable(false)//tidak bisa tekan tombol back 
        //jika pilih yess 
        .setPositiveButton("Ya", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          finish(); 
         } 
        }) 
        //jika pilih no 
        .setNegativeButton("Tidak", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          dialog.cancel(); 
         } 
        }).show(); 
     } 

     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     drawer.closeDrawer(GravityCompat.START); 
     return true; 
    } 

} 

和我有setSupportActionBar(toolbar);
一個錯誤,你能幫我嗎?

+2

https://stackoverflow.com/help/how-to-ask –

+0

請附上您的清單文件 –

+0

看起來你MainActivity主題已經在款式有動作條,設置您的活動主題noActionBar再試試這個setSupportActionBar(工具欄); –

回答

0

試試你的活動的父主題設置爲Theme.AppCompat.Light.NoActionBar

的重要組成部分,是「NoActionBar

然後你就可以在你的佈局中使用自定義ToolBar

+0

泰克你的建議 –

0

套裝windowNoTitle和「windowActionBar`在styles.xml的基本主題,並在AndroidManifest.xml這個主題應用到您的應用程序

<!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="windowNoTitle">true</item> 
     <item name="windowActionBar">false</item> 

    </style> 
+0

謝謝你的答案 –

相關問題