2016-06-09 92 views
0

我正在創建一個具有包含多個網站鏈接的導航抽屜的項目。我想在單個webview中顯示所有的網站鏈接,以便在應用程序中打開它們。我嘗試了所有發佈和可能的解決方案,但沒有任何工作。請任何人都可以幫助我.. !!在單個webview中打開多個鏈接

activity_mail.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"> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <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" /> 

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

activity_webview.xml 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<WebView 
android:id="@+id/activity_main_webview" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:visibility="gone"/> 

<ProgressBar 
android:id="@+id/progressBar1" 
style="?android:attr/progressBarStyleLarge" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:layout_centerHorizontal="true" 
android:indeterminate="false" 
android:layout_gravity="center_horizontal" /> 

</LinearLayout> 

nav_header_main.xml 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/nav_header_height" 
    android:background="@drawable/side_nav_bar" 
    android:gravity="bottom" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:src="@drawable/grovi" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:text="GROVEUS" 
     android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="www.groveus.com" /> 

</LinearLayout> 

Inside Menu Folder: activity_main_drawer.xml 
<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

    <group android:checkableBehavior="single"> 
     <item android:title="Academics"> 
     <menu> 
      <item 
       android:id="@+id/classmaster" 
       android:icon="@drawable/iconred" 
       android:title="Class Master" 
      /> 
      <item 

       android:id="@+id/admission" 
       android:icon="@drawable/iconred" 
       android:title="Admission" 
      /> 
      <item 

       android:id="@+id/uploadmarksheet" 
       android:icon="@drawable/iconred" 
       android:title="Upload Marksheet CSV" 
       /> 
      <item 

       android:id="@+id/createexam" 
       android:icon="@drawable/iconred" 
       android:title="Create Exam" 
       /> 
      <item 

       android:id="@+id/subjectassign" 
       android:icon="@drawable/iconred" 
       android:title="Subject Assign" 
       /> 
      <item 

       android:id="@+id/facultymaster" 
       android:icon="@drawable/iconred" 
       android:title="Faculty Master" 
       /> 
     </menu> 
     </item> 
     <item android:title="SMS Master"> 
      <menu> 
       <item 
        android:id="@+id/events" 
        android:icon="@drawable/iconred" 
        android:title="Events" 
        /> 
       <item 

        android:id="@+id/sendsms" 
        android:icon="@drawable/iconred" 
        android:title="Send SMS" 
        /> 
       <item 

        android:id="@+id/delivery" 
        android:icon="@drawable/iconred" 
        android:title="Delivery Reports" 
        /> 
       <item 

        android:id="@+id/schedule" 
        android:icon="@drawable/iconred" 
        android:title="Schedule SMS" 
        /> 
       <item 

        android:id="@+id/settings" 
        android:icon="@drawable/iconred" 
        android:title="SMS Settings" 
        /> 
       <item 

        android:id="@+id/freesms" 
        android:icon="@drawable/iconred" 
        android:title="Free SMS Excel" 
        /> 
      </menu> 
     </item> 
     <item android:title="Administration"> 
      <menu> 
       <item 
        android:id="@+id/userpriviledges" 
        android:icon="@drawable/iconred" 
        android:title="User Priviledges" 
        /> 
       <item 

        android:id="@+id/usermaster" 
        android:icon="@drawable/iconred" 
        android:title="User Master" 
        /> 
       <item 

        android:id="@+id/accountdetails" 
        android:icon="@drawable/iconred" 
        android:title="Account Details" 
        /> 
       <item 

        android:id="@+id/thememaster" 
        android:icon="@drawable/iconred" 
        android:title="Theme Master" 
        /> 
      </menu> 
     </item> 
    </group> 

</menu> 


MainActivity.java 
package com.example.piku.groveus; 

import android.content.Context; 
import android.content.Intent; 
import android.graphics.Bitmap; 
import android.net.Uri; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
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.webkit.WebSettings; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

import com.parse.Parse; 
import com.parse.ParseInstallation; 
import com.parse.ParseObject; 
import com.pushbots.push.Pushbots; 

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); 
     Pushbots.sharedInstance().init(this); 
     Pushbots.sharedInstance().setCustomHandler(customHandler.class); 
     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() 
     { 
      @Override 
      public void onClick(View view) 
      { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 

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

    @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.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 

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

     int id = item.getItemId(); 



     if (id == R.id.classmaster) 
     { 
      Intent b = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/class_master")); 
      startActivity(b); 
     } 
     else if (id == R.id.admission) 
     { 
      Intent b = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/admission")); 
      startActivity(b); 
     } 
     else if (id == R.id.uploadmarksheet) 
     { 
      Intent c = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/upload _csv")); 
      startActivity(c); 
     } 
     else if (id == R.id.createexam) 
     { 
      Intent d = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/exam_master")); 
      startActivity(d); 
     } 
     else if(id == R.id.subjectassign) 
     { 
      Intent e = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/subject_assign")); 
      startActivity(e); 
     } 
     else if(id == R.id.facultymaster) 
     { 
      Intent f = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/faculty_master")); 
      startActivity(f); 
     } 
     else if(id == R.id.events) 
     { 
      Intent g = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/events")); 
      startActivity(g); 
     } 
     else if(id == R.id.sendsms) 
     { 
      Intent h = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/sms")); 
      startActivity(h); 
     } 
     else if(id == R.id.delivery) 
     { 
      Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/sms_reports")); 
      startActivity(i); 
     } 
     else if(id == R.id.schedule) 
     { 
      Intent j = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/sms_log")); 
      startActivity(j); 
     } 
     else if(id == R.id.settings) 
     { 
      Intent k = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/sms_alerts")); 
      startActivity(k); 
     } 
     else if(id == R.id.freesms) 
     { 
      Intent l = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/fees_sms")); 
      startActivity(l); 
     } 
     else if(id == R.id.userpriviledges) 
     { 
      Intent m = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/user_privileges")); 
      startActivity(m); 
     } 
     else if(id == R.id.usermaster) 
     { 
      Intent n = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/user_master")); 
      startActivity(n); 
     } 
     else if(id == R.id.accountdetails) 
     { 
      Intent o = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/change_pwd")); 
      startActivity(o); 
     } 
     else if(id == R.id.thememaster) 
     { 
      Intent p = new Intent(Intent.ACTION_VIEW, Uri.parse("http://app.schoolbios.com/main#/theme_master")); 
      startActivity(p); 
     } 


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


MyAppWebViewClient.java 
package com.example.piku.groveus; 

import android.content.Intent; 
import android.net.Uri; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

public class MyAppWebViewClient extends WebViewClient 
{ 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) 
    { 
     if(Uri.parse(url).getHost().endsWith("schoolbios.com")) 
     { 
      return false; 
     } 

     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     view.getContext().startActivity(intent); 
     return true; 
    } 
} 

回答

0

您可以創建自己的網絡視圖活動,並在選擇導航項時像下面那樣開始活動。

Intent startWebViewIntent=new Intent(this,SurahWebviewActivity.class); 
    startWebViewIntent.putExtra("PrayerTime",1); 
    startActivity(startWebViewIntent); 

但是在您的代碼中,您可以創建一個方法來加載帶有鏈接的Web視圖,並在選擇導航項時調用該方法。它可能像下面這樣。

public boolean onNavigationItemSelected(MenuItem item) 
    { 
     // Handle navigation view item clicks here. 

     int id = item.getItemId(); 

     if (id == R.id.classmaster) 
     { 
      URI uri=Uri.parse("http://app.schoolbios.com/main#/class_master")); 
      populateWebView(uri); 
     } 
} 

private void populateWebView(URI uri){ 
    thisWebView.loadUrl(uri); 
} 
+0

陶氏我必須實現兩個代碼才能獲得不同鏈接的網頁瀏覽量? – Abhro

+0

「PlayerTime」和1是什麼意思? – Abhro

+0

我沒有清楚地得到第一種方法。而第二種方法不起作用。 – Abhro

相關問題