Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我想通过android应用程序的菜单项访问我的管理面板页面_Java_Android_Url_Menu - Fatal编程技术网

Java 我想通过android应用程序的菜单项访问我的管理面板页面

Java 我想通过android应用程序的菜单项访问我的管理面板页面,java,android,url,menu,Java,Android,Url,Menu,在我的android应用程序中,我有一个菜单项注销。我想在我的面板中添加另一个菜单项,该菜单项将重定向到管理面板页面gmumbai.co.In/admin。如何完成此操作。请帮助我提供示例代码。提前感谢 public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenu

在我的android应用程序中,我有一个菜单项注销。我想在我的面板中添加另一个菜单项,该菜单项将重定向到管理面板页面gmumbai.co.In/admin。如何完成此操作。请帮助我提供示例代码。提前感谢

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_overview, 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();
        Intent intent;

        switch (item.getItemId()) {
            case R.id.action_logout:
                app = ((MyApplication) getApplicationContext());
                app.logOut();
                intent = new Intent(overview.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                overview.this.startActivity(intent);
                overview.this.finish();
                return true;
            case R.id.action_MyPanel:
                Uri uri=Uri.parse("http://gmumbai.co.in/admin");
                overview.this.startActivity(new Intent (Intent.ACTION_VIEW,uri));
                overview.this.finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}

    <menu 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" tools:context="com.gmumbai.gvendor.overview">
    <item android:id="@+id/action_logout" android:title="@string/action_logout"
        android:orderInCategory="100" app:showAsAction="never" />
    <item android:id="@+id/action_MyPanel" android:title="@string/action_MyPanel"
        android:orderInCategory="100" app:showAsAction="never" />
</menu>
public boolean oncreateoptions菜单(菜单菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.menu\U概述,菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
意图;
开关(item.getItemId()){
案例R.id.行动\注销:
app=((MyApplication)getApplicationContext());
app.logOut();
意图=新意图(overview.this、LoginActivity.class);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_NEW_TASK);
概述。此。startActivity(意向);
overview.this.finish();
返回true;
案例R.id.action_MyPanel:
Uri=Uri.parse(“http://gmumbai.co.in/admin");
概述.this.startActivity(新意图(Intent.ACTION_视图,uri));
overview.this.finish();
返回true;
违约:
返回super.onOptionsItemSelected(项目);
}
}
}

要添加菜单项,请尝试以下操作:

res/menu/main_menu.xml

<menu 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" tools:context=".MainActivity">
    <item
        android:id="@+id/action_logout"
        android:icon="@drawable/ic_logout"
        android:title="Logout"
        app:showAsAction="always|collapseActionView" />
    <item
        android:id="@+id/action_redirAdmin"
        android:icon="@drawable/admin_console"
        android:title="Admin Console"
        app:showAsAction="always|collapseActionView">
    </item>
</menu>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context=".MainActivity" >  

    <WebView  
        android:id="@+id/adminConsoleWebView"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:layout_alignParentTop="true"  
        android:layout_centerHorizontal="true"  
        android:layout_marginTop="42dp" />  
  </RelativeLayout>
如果您试图在视图中显示网页,请确保在AdminConsole.java中有一个WebView

要添加WebView,请尝试以下操作:

管理控制台活动.xml

<menu 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" tools:context=".MainActivity">
    <item
        android:id="@+id/action_logout"
        android:icon="@drawable/ic_logout"
        android:title="Logout"
        app:showAsAction="always|collapseActionView" />
    <item
        android:id="@+id/action_redirAdmin"
        android:icon="@drawable/admin_console"
        android:title="Admin Console"
        app:showAsAction="always|collapseActionView">
    </item>
</menu>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context=".MainActivity" >  

    <WebView  
        android:id="@+id/adminConsoleWebView"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:layout_alignParentTop="true"  
        android:layout_centerHorizontal="true"  
        android:layout_marginTop="42dp" />  
  </RelativeLayout>

非常感谢。我会试试这个。你能指导我如何在java类中添加webview吗?请看我更新的答案。如果有帮助,请将其标记为正确/竖起大拇指。谢谢你想通过点击菜单项打开网页浏览器吗?你是怎么做到的?在此处显示您的代码/工作。StackOverflow不是代码编写服务。如果您的代码有问题,请提供最小、完整和可验证的示例。请查看我的代码。我已添加了两个菜单项。但我无法看到第二个菜单项“我的面板”,我想在其中访问我的管理面板页面。因此,我只要求提供示例代码。