我怎么能翻译这个字符串? - Android

时间:2017-03-25 16:08:37

标签: android

我的应用程序上有这个代码:

public class MainActivity extends ActionBarActivity implements MaterialTabListener {
MaterialTabHost tabHost;
ViewPager pager;
ViewPagerAdapter adapter;
private String[] tabs = {"Home","Category","Favourite"};
Toolbar toolbar;
String strMessage;
private AdView mAdView;
private InterstitialAd mInterstitial;

我想从此代码翻译:

private String[] tabs = {"Home","Category","Favourite"};

但是当我把R.string.menu_home放进去的时候,它给了我一些错误。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

https://developer.android.com/guide/topics/resources/string-resource.html

<?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string-array
            name="string_array_name">
            <item>Home</item>
            <item>Category</item>
            <item>Favourite</item>
        </string-array>
    </resources>

在String数组中拉出来

Resources res = getResources();
String[] tabs = res.getStringArray(R.array.string_array_name);