Android 更改“材质”选项卡项的语言

Android 更改“材质”选项卡项的语言,android,android-tablayout,Android,Android Tablayout,通过定义多个字符串文件,我可以选择在我的应用程序中支持多种语言,用户可以根据需要切换到适当的语言。更改语言会在任何地方生效,但选项卡项目和TabLayout上方的工具栏除外。谢谢 下面是我的XML文件的代码 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.a

通过定义多个字符串文件,我可以选择在我的应用程序中支持多种语言,用户可以根据需要切换到适当的语言。更改语言会在任何地方生效,但选项卡项目和TabLayout上方的工具栏除外。谢谢

下面是我的XML文件的代码

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            app:tabTextAppearance="@style/TabTextAppearance"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

在代码中,应该有一个扩展FragmentPagerAdaper的类。FragmentPagerAdapter类公开了一个名为“getPageTitle”的方法(更多信息,请参见此处)。重写getPageTitle方法并返回所需的标题。代码如下

class ViewPagerAdapter扩展了FragmentPagerAdapter{
私有最终列表MFFragmentList=new ArrayList();
私有最终列表MFFragmentTitleList=new ArrayList();
公共视图页面编辑器(碎片管理器){
高级经理;
}
@凌驾
公共片段getItem(int位置){
Fragment currentFragment=MFFragmentList.get(位置);
返回电流片段;
}
@凌驾
public int getCount(){
返回MFFragmentList.size();
}
public void addFragment(片段片段,字符串标题){
添加(片段);
MFFragmentTitleList.add(标题);
}
@凌驾
公共字符序列getPageTitle(int位置){
开关(位置){
案例0:
返回getString(R.string.your\u title\u 0);
案例1:
返回getString(R.string.your_title_1);
违约:
返回getString(R.string.your\u title\u默认值)
}
}
}

我通过使用BaseActivity而不是AppCompativity扩展TabsActivity获得了预期的结果

public class TabsActivity extends AppCompatActivity
改为

public class TabsActivity extends BaseActivity

@A.Wahab是的,我不知道-ve marking的原因我发布了我设置标签标题的方式,在技术上与您的没有什么不同,但问题是语言更改没有生效。只有英文标题保留在那里我觉得很奇怪,你有没有试着把getString()函数的结果记录在logcat中?
public class TabsActivity extends BaseActivity