我在 strings.xml 文件中创建了一个字符串数组,我想要访问数组 我的布局来填补我的筹码。我该怎么做?
这是我的 strings.xml
<string-array name="shortcutCategoryNames">
<item>Digital</item>
<item>Clothes</item>
<item>Sport</item>
<item>Cosmetics</item>
</string-array>
这是我的布局
<com.google.android.material.chip.ChipGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.chip.Chip
android:id="@+id/chp_digital"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<com.google.android.material.chip.Chip
android:id="@+id/chp_clothes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<!-- rest of Chips-->
</com.google.android.material.chip.ChipGroup>
最佳答案
您可以使用以下方法获取字符串数组。
ArrayList<String> tagList = new ArrayList();
String[] someArray = getResources().getStringArray(R.array.shortcutCategoryNames);
tagList.addAll(Arrays.asList(someArray));
关于android - 如何在 android 布局中使用 string.xml 中的字符串数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55355183/