【安卓学习之常见问题】android.R.string.yes获取到的是英文

█ 【安卓学习之常见问题】android.R.string.yes获取到的是英文


█ 系列文章目录

提示:这里是收集了无人机的相关文章

  • 【安卓学习之DroidPlanner】1.Arduino学习
  • 【安卓学习之DroidPlanner】FlightActivity的启动过程

█ 文章目录

  • █ 【安卓学习之常见问题】android.R.string.yes获取到的是英文
  • █ 系列文章目录
  • █ 文章目录
  • █ 读前说明
  • █ 问题描述:
      • 中文系统中,android.R.string.yes得到的值是“OK”:
      • 中文系统中,android.R.string.ok得到的值是“确定”:
      • 难道android.R.string.yes没有中文翻译?
  • █ 原因分析:
      • 1.查看android.R.string.yes值是正常的
      • 2.看起其他代码android.R.string.yes值是正常的
  • █ 解决方案:
      • Context 错误,在Fragment中应该修改为 getContext()就正常了
  • █ 相关资料


█ 读前说明

  • 本文通过学习别人写demo,学习一些课件,参考一些博客,’学习相关知识,如果涉及侵权请告知
  • 本文只简单罗列相关的代码实现过程
  • 涉及到的逻辑以及说明也只是简单介绍,主要当做笔记,了解过程而已

█ 问题描述:

中文系统中,android.R.string.yes得到的值是“OK”:

  • 执行代码
  getActivity().getApplicationContext().getString(android.R.string.yes)

中文系统中,android.R.string.ok得到的值是“确定”:

  • 执行代码
  getActivity().getApplicationContext().getString(android.R.string.ok)

难道android.R.string.yes没有中文翻译?


█ 原因分析:

1.查看android.R.string.yes值是正常的

【安卓学习之常见问题】android.R.string.yes获取到的是英文_第1张图片

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/strings.xml
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

    <!-- Preference framework strings. -->
    <string name="ok">OK</string>
    <!-- Preference framework strings. -->
    <string name="cancel">Cancel</string>
    <!-- Preference framework strings. -->
    <string name="yes">OK</string>
    <!-- Preference framework strings. -->
    <string name="no">Cancel</string>
    <!-- This is the generic "attention" string to be used in attention dialogs.  Typically
         combined with setIconAttribute(android.R.attr.alertDialogIcon)
         (or setIcon(android.R.drawable.ic_dialog_alert) on legacy versions of the platform) -->
    <string name="dialog_alert_title">Attention</string>

    <!-- Text shown by list fragment when waiting for data to display. -->
    <string name="loading">Loading\u2026</string>

    <!-- Default text for a button that can be toggled on and off. -->
    <string name="capital_on">ON</string>
    <!-- Default text for a button that can be toggled on and off. -->
    <string name="capital_off">OFF</string>
</resources>
<?xml version="1.0" encoding="UTF-8"?>
<!-- 
/* //device/apps/common/assets/res/any/strings.xml
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
 -->

<resources xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

    <string name="ok" msgid="5970060430562524910">"确定"</string>
    <string name="cancel" msgid="6442560571259935130">"取消"</string>
    <string name="yes" msgid="5362982303337969312">"确定"</string>
    <string name="no" msgid="5141531044935541497">"取消"</string>
    <string name="dialog_alert_title" msgid="2049658708609043103">"注意"</string>
    <string name="loading" msgid="7933681260296021180">"正在加载..."</string>
    <string name="capital_on" msgid="1544682755514494298">"开启"</string>
    <string name="capital_off" msgid="6815870386972805832">"关闭"</string>
</resources>

2.看起其他代码android.R.string.yes值是正常的

  getContext().getString(android.R.string.yes)
  getString(android.R.string.yes)

█ 解决方案:

Context 错误,在Fragment中应该修改为 getContext()就正常了

  getContext().getString(android.R.string.yes)

⚡️复制时,需要注意细节


█ 相关资料

提示:这里是参考的相关文章

  1. DialogFragment与一般的AlertDialog的区别在哪里? - 知乎

提示:转载请注明出处:
https://blog.csdn.net/ljb568838953/article/details/114441823

你可能感兴趣的:(#,android常见问题,常见问题汇集)