通过菜单单击更改字符串

时间:2019-05-03 14:32:25

标签: java android android-menu

我的android studio项目中有Constant.java。而且我有适合我的应用程序的菜单。我想用菜单项单击更改字符串。我该怎么办?

这是我的constant.java文件。

public class Constant implements Serializable{

    /**
     *
     */


    private static final long serialVersionUID = 1L;

    //server url
    public static final String SERVER_URL= BuildConfig.server_url;


    public static final String IMAGE_PATH_URL =SERVER_URL+"images/";

    public static final String CATEGORY_URL = SERVER_URL+"api.php?cat_list";
}

这是我的cabinet_menu.xml文件

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

    <group android:checkableBehavior="single">

        <item
            android:id="@+id/menu_go_home"
            android:checked="true"
            android:icon="@drawable/ic_d_home"
            android:title="@string/menu_home" />

        <item
            android:id="@+id/menu_go_category"
            android:checked="false"
            android:icon="@drawable/ic_d_category"
            android:title="@string/menu_category" />
        <item
            android:id="@+id/menu_go_diziler"
            android:checked="false"
            android:icon="@drawable/ic_d_category"
            android:title="Diziler" />

        <item
            android:id="@+id/menu_go_latest"
            android:checked="false"
            android:icon="@drawable/ic_d_latest"
            android:title="@string/menu_latest" />

        <item
            android:id="@+id/menu_go_all"
            android:checked="false"
            android:icon="@drawable/ic_d_video"
            android:title="@string/menu_all" />

        <item
            android:id="@+id/menu_go_favourite"
            android:checked="false"
            android:icon="@drawable/ic_d_favorite"
            android:title="@string/menu_favorite" />

        <item
            android:id="@+id/menu_go_rate"
            android:checkable="false"
            android:icon="@drawable/ic_d_rate"
            android:title="@string/menu_rate" />

        <item
            android:id="@+id/menu_go_share"
            android:checkable="false"
            android:icon="@drawable/ic_d_share"
            android:title="@string/menu_share" />
        <item
            android:id="@+id/menu_go_more"
            android:checkable="false"
            android:icon="@drawable/ic_d_more"
            android:title="@string/menu_more" />

        <item
            android:id="@+id/menu_go_about"
            android:checked="false"
            android:icon="@drawable/ic_d_about"
            android:title="@string/menu_about" />

        <item
            android:id="@+id/menu_go_privacy"
            android:checked="false"
            android:icon="@drawable/ic_d_privacy"
            android:title="@string/menu_privacy" />



    </group>
</menu>

例如,现在当我单击具有android:id="@+id/menu_go_category" id的菜单项时,我想用 public static final String CATEGORY_URL = SERVER_URL+"api.php?cat_list";public static final String CATEGORY_URL = SERVER_URL+"api.php?menu_go_category (or anything else)

我该怎么做?

注意:我的Constant.java文件和药盒文件的目录都在不同的包中

1 个答案:

答案 0 :(得分:1)

尝试一下。

100