Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.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 按字符串更改导航抽屉名称项_Java_Android_Android Fragments_Navigation Drawer - Fatal编程技术网

Java 按字符串更改导航抽屉名称项

Java 按字符串更改导航抽屉名称项,java,android,android-fragments,navigation-drawer,Java,Android,Android Fragments,Navigation Drawer,我需要一种使用字符串而不是性能的方法,MALI…我试图用@string/resource\u name来替换它们,但它不起作用,当我打开菜单时,它显示的是链接名@string/resource\u name,而不是链接名 主要活动: //Show the items into the menu. @Override protected NavDrawerActivityConfiguration getNavDrawerConfiguration() { NavDrawerItem[

我需要一种使用字符串而不是性能的方法,MALI…我试图用@string/resource\u name来替换它们,但它不起作用,当我打开菜单时,它显示的是链接名@string/resource\u name,而不是链接名

主要活动:

 //Show the items into the menu.
@Override
protected NavDrawerActivityConfiguration getNavDrawerConfiguration() {

    NavDrawerItem[] menu = new NavDrawerItem[] {

            //This sets the name, mine is a multilanguage app so I wanna find a way to use @string/resource instead
            //of "PERFORMANCE", ecc.
            NavMenuItem.create(1,"PERFORMANCE", "", false, this),
            NavMenuItem.create(2, "MALI", "", false, this), 
            NavMenuItem.create(3, "BATTERY", "", false, this),
            NavMenuItem.create(4, "CPU", "", false, this), 
            NavMenuItem.create(5, "MISC", "", false, this),
            NavMenuItem.create(6, "NET", "", false, this),
            NavMenuItem.create(7, "HELP", "", false, this),
            NavMenuItem.create(8, "GUIDE", "", false, this)};

    NavDrawerActivityConfiguration navDrawerActivityConfiguration = new NavDrawerActivityConfiguration();
    navDrawerActivityConfiguration.setMainLayout(R.layout.main);
    navDrawerActivityConfiguration.setDrawerLayoutId(R.id.drawer_layout);
    navDrawerActivityConfiguration.setLeftDrawerId(R.id.left_drawer);
    navDrawerActivityConfiguration.setNavItems(menu);
    navDrawerActivityConfiguration.setDrawerShadow(R.drawable.drawer_shadow);       
    navDrawerActivityConfiguration.setDrawerOpenDesc(R.string.drawer_open);
    navDrawerActivityConfiguration.setDrawerCloseDesc(R.string.drawer_close);
    navDrawerActivityConfiguration.setBaseAdapter(
        new NavDrawerAdapter(this, R.layout.navdrawer_item, menu ));
    return navDrawerActivityConfiguration;
}
NavmenuItem:

    public class NavMenuItem implements NavDrawerItem {

public static final int ITEM_TYPE = 1 ;

private int id ;
private String label ;  
private boolean updateActionBarTitle ;

private NavMenuItem() {
}

public static NavMenuItem create( int id, String label, String icon, boolean updateActionBarTitle, Context context ) {
    NavMenuItem item = new NavMenuItem();
    item.setId(id);
    item.setLabel(label);
    item.setUpdateActionBarTitle(updateActionBarTitle);
    return item;
}

@Override
public int getType() {
    return ITEM_TYPE;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getLabel() {
    return label;
}

public void setLabel(String label) {
    this.label = label;
}


@Override
public boolean isEnabled() {
    return true;
}

@Override
public boolean updateActionBarTitle() {
    return this.updateActionBarTitle;
}

public void setUpdateActionBarTitle(boolean updateActionBarTitle) {
    this.updateActionBarTitle = updateActionBarTitle;
}
}

纳瓦雷特:

 public interface NavDrawerItem {
public int getId();
public String getLabel();
public int getType();
public boolean isEnabled();
public boolean updateActionBarTitle();
}

像这样尝试:

NavDrawerItem[] menu = new NavDrawerItem[] {

        //This sets the name, mine is a multilanguage app so I wanna find a way to use @string/resource instead
        //of "PERFORMANCE", ecc.
        NavMenuItem.create(1,getString(R.string.performance_name), "", false, this) 
....

您是否正在寻找:

getString(R.string.name);  
?

你需要一个背景。在片段或活动中,您可以只调用getString,但如果出于任何原因无法使用它,那么它只是

context.getResources().getString(R.string.name);

他说他的代码正在运行中,所以他可以直接使用GetStrings。他确实做到了,谢谢。值得注意的是,getString只是另一个调用的快捷方式。在一个关于getString的问题中很难包含很多有趣的信息,所以我就不提了