radio button 旁边放图片以及强制程序本地化以及string含有参数

本文介绍了一种在Android应用中强制使用特定语言的方法,并展示了如何通过创建不同语言版本的资源文件来实现这一目标。此外,还提供了一个使用MessageFormat进行字符串格式化的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<RadioButton android:id="@+id/RadioButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:drawableLeft="@drawable/icon"
android:drawableRight="@drawable/icon"
android:drawableTop="@drawable/icon"
android:drawableBottom="@drawable/icon" />

 

有时候为了使版本能够适用不同的地区 而选择了不同文件夹

其实有时候还可以强制使用

<activity android:name=".M1" android:configChanges="locale" android:label="@string/app_name" />
一定要加上啊

然后呢代码

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String languageToLoad = "cn";
    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
    getBaseContext().getResources().getDisplayMetrics());
    this.setContentView(R.layout.main);
  }
剩下的就很简单了

你要做的就是 在main假设存在一个button,你想在上面设置文字 ,你想有英文的或者中文的,但是你想你手机使用的时候先强制使用中文

那么你只需要在

res中新建一个文件夹 values-cn 然后里面的参数和vvalues中的string一样就可以了 只要内容不同

然后你运行程序就会发现 原来先运行的是中文的

 

3.

 String msg = getResources().getString(R.string.text_c);       

  msg = java.text.MessageFormat.format(msg, "foo", "bar", locale);

 

 

 <string name="text_c">This string uses message formatting. In the current locale, {1} comes before {0} and the current locale is {2}.</string>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值