在Android中可以使用字符串数组资源。

  在资源文件中定义方式如下:

  < ?xml version="1.0" encoding="utf-8"?>

  < resources>

  < string-array name="sa">

<item>兑换</item>
<item>积分排行</item>
<item>积分详情</item>
<item>我的兑换</item>
<item>规则通知</item>

 

  < /string-array>

  < /resources>

  在Activity中取得方法如下:

  String[] sa = getResources().getStringArray(R.array.sa);

  还可以使用整数数组。

  定义名称为integer-array。

  调用方法为getIntArray(< id>)。

  使用方式同上。



那么在程序中如何获取咱们在配置文件中定义好的字符串数组呢?

Resources res = this.getResources(); //基本上获取在配置文件中的信息都要用到Resources,所以大家只需要查看下这个Resourece类得API文档基本都能找到自己所需要的东西
String[] arr = res.getStringArray(R.array.card_items);

相关文章:

  • 2021-07-11
  • 2021-11-11
  • 2022-12-23
  • 2021-12-04
  • 2021-08-16
  • 2021-11-14
  • 2021-06-22
  • 2021-11-14
猜你喜欢
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-02-10
  • 2022-12-23
相关资源
相似解决方案