我使用导航抽屉制作了一个简单的WebView应用程序,它在模拟器上的工作方式,我不会更高兴,但后来我安装在我的Galaxy S6上,当我打开导航时它真的落后了抽屉,在我姐姐的S5上,应用程序崩溃了。我正在接近我的截止日期,我不知道该怎么办......
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private WebView mWebView;
DrawerLayout drawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cat8Fragment cat8Fragment = new cat8Fragment();
FragmentManager manager = getSupportFragmentManager();
manager .beginTransaction().replace(R.id.RelativeLayout_for_fragment, cat8Fragment, cat8Fragment.getTag()).commit();
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application/wp-admin/press-this.php");
}
});
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.addDrawerListener(toggle);
toggle.syncState();
toggle.setDrawerIndicatorEnabled(false);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application");
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebViewClient(new MyAppWebViewClient());
}
@Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@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.menuRight) {
if(drawer.isDrawerOpen(Gravity.RIGHT)){
drawer.closeDrawer(Gravity.RIGHT);
}
else {
drawer.openDrawer(Gravity.RIGHT);
}
return true;
}
if (id == R.id.home22)
{
cat9Fragment cat9Fragment = new cat9Fragment();
FragmentManager manager = getSupportFragmentManager();
manager .beginTransaction().replace(R.id.RelativeLayout_for_fragment, cat9Fragment, cat9Fragment.getTag()).commit();
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application/");
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
FragmentManager fragmentManager = getSupportFragmentManager();
if (id == R.id.cat1) {
Toast.makeText(this, "פעולות ופעילויות גן עד ג'", Toast.LENGTH_SHORT).show();
cat1Fragment cat1Fragment = new cat1Fragment();
FragmentManager manager = getSupportFragmentManager();
manager .beginTransaction().replace(R.id.RelativeLayout_for_fragment, cat1Fragment, cat1Fragment.getTag()).commit();
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application/%d7%a4%d7%a2%d7%95%d7%9c%d7%95%d7%aa-%d7%95%d7%a4%d7%a2%d7%99%d7%9c%d7%95%d7%99%d7%95%d7%aa-%d7%92%d7%9f-%d7%a2%d7%93-%d7%92/");
} else if (id == R.id.cat2) {
Toast.makeText(this, "פעולות ופעילויות ד'-ו' ", Toast.LENGTH_SHORT).show();
cat2Fragment cat2Fragment = new cat2Fragment();
FragmentManager manager = getSupportFragmentManager();
manager .beginTransaction().replace(R.id.RelativeLayout_for_fragment, cat2Fragment, cat2Fragment.getTag()).commit();
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application/%D7%A4%D7%A2%D7%95%D7%9C%D7%95%D7%AA-%D7%95%D7%A4%D7%A2%D7%99%D7%9C%D7%95%D7%99%D7%95%D7%AA-%D7%93-%D7%95/");
} else if (id == R.id.cat3) {
Toast.makeText(this, "פעולות ופעילויות ז'-ט' ", Toast.LENGTH_SHORT).show();
cat3Fragment cat3Fragment = new cat3Fragment();
FragmentManager manager = getSupportFragmentManager();
manager .beginTransaction().replace(R.id.RelativeLayout_for_fragment, cat3Fragment, cat3Fragment.getTag()).commit();
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application/%D7%A4%D7%A2%D7%95%D7%9C%D7%95%D7%AA-%D7%95%D7%A4%D7%A2%D7%99%D7%9C%D7%95%D7%99%D7%95%D7%AA-%D7%96-%D7%98/");
} else if (id == R.id.cat4) {
Toast.makeText(this, "פעולות ופעילויות י'-ב ", Toast.LENGTH_SHORT).show();
cat4Fragment cat4Fragment = new cat4Fragment();
FragmentManager manager = getSupportFragmentManager();
manager .beginTransaction().replace(R.id.RelativeLayout_for_fragment, cat4Fragment, cat4Fragment.getTag()).commit();
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application/%D7%A4%D7%A2%D7%95%D7%9C%D7%95%D7%AA-%D7%95%D7%A4%D7%A2%D7%99%D7%9C%D7%95%D7%99%D7%95%D7%AA-%D7%99-%D7%99%D7%91/");
}else if (id == R.id.randact) {
Toast.makeText(this, "פעולה רנדומלית", Toast.LENGTH_SHORT).show();
cat5Fragment cat5Fragment = new cat5Fragment();
FragmentManager manager = getSupportFragmentManager();
manager .beginTransaction().replace(R.id.RelativeLayout_for_fragment, cat5Fragment, cat5Fragment.getTag()).commit();
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application/%D7%A4%D7%A2%D7%95%D7%9C%D7%94-%D7%A8%D7%A0%D7%93%D7%95%D7%9E%D7%9C%D7%99%D7%AA-2/");
}else if (id == R.id.gamelib) {
Toast.makeText(this, "ספריית המשחקים", Toast.LENGTH_SHORT).show();
cat6Fragment cat6Fragment = new cat6Fragment();
FragmentManager manager = getSupportFragmentManager();
manager .beginTransaction().replace(R.id.RelativeLayout_for_fragment, cat6Fragment, cat6Fragment.getTag()).commit();
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application/%D7%A1%D7%A4%D7%A8%D7%99%D7%99%D7%AA-%D7%94%D7%9E%D7%A9%D7%97%D7%A7%D7%99%D7%9D/");
} else if (id == R.id.pinukim) {
Toast.makeText(this, "צ'ופרים ופינוקים", Toast.LENGTH_SHORT).show();
cat7Fragment cat7Fragment = new cat7Fragment();
FragmentManager manager = getSupportFragmentManager();
manager .beginTransaction().replace(R.id.RelativeLayout_for_fragment, cat7Fragment, cat7Fragment.getTag()).commit();
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://peulibrary.com/application/%D7%A4%D7%99%D7%A0%D7%95%D7%A7%D7%99%D7%9D-%D7%95%D7%A6%D7%95%D7%A4%D7%A8%D7%99%D7%9D/");
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.END);
new Thread(new Runnable() {
public void run() {
try {
TimeUnit.MILLISECONDS.sleep(300);
//Here call you fragmentManager
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
return true;
}
这是我的主要代码,有人可以告诉我这里有什么问题吗? 谢谢。