欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

Android

當(dāng)前位置:主頁 > 軟件編程 > Android >

android 使用kotlin 實(shí)現(xiàn)點(diǎn)擊更換全局語言(中日英切換)

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:Android|點(diǎn)擊: 次

> 因?yàn)槲业墓ぷ饕胟otlin所以今天在這里給大家總結(jié)一下關(guān)于全局語言切換的kotlin語言實(shí)現(xiàn)實(shí)現(xiàn),很簡單,希望在這里可以幫助到有需要的同學(xué),下面簡單說一下實(shí)現(xiàn)步驟,會(huì)把運(yùn)行截圖放在最后<

注:在這里我要說一下,我知道kotlin不太普及,如果有的同學(xué)需要java版的,可以在通讀一遍代碼,了解了之后把kotlin轉(zhuǎn)化為java,因?yàn)閗otlin與java是互通的,代碼的一些關(guān)鍵點(diǎn),java語言該怎么寫還怎么寫,如果有不明白的可以留言

第一步:簡單寫一下選擇語言的布局就好,會(huì)用到點(diǎn)擊事件,因?yàn)槲乙玫饺N語言,可以Button控件,TextView控件,都可以

第二步:可以看下面截圖

1.右鍵res



2.new–>android resource file



3.輸入filename,在下滿local選擇需要的語言



4.最后像這樣,然后在里面輸入所需要控件的語言,在xml空間中運(yùn)用到,比如 android:text=“@strings/定義的名字”,注意這4個(gè)string里面所有控件的數(shù)量與名字都要相同


第二步:這里要用到CommonUtil工具類,因?yàn)閗otlin與java是互通的,我把代碼寫在下面可以直接用

public class CommonUtil {
 public static void configLanguage(Context mContext, String language) {
 Configuration config = mContext.getResources().getConfiguration();
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
 if (language.equals("CHINESE")) {
 config.locale = Locale.SIMPLIFIED_CHINESE;
 } else if (language.equals("ENGLISH")) {
 config.locale = Locale.US;
 } else if(language.equals("JAPANESE")){
 config.locale = Locale.JAPAN;
 }else {
 config.locale = Locale.SIMPLIFIED_CHINESE;
 }
 } else {
 if (language.equals("CHINESE")) {
 config.locale = Locale.CHINESE;
 } else if (language.equals("ENGLISH")) {
 config.locale = Locale.ENGLISH;
 } else if (language.equals("JAPANESE")){
 config.locale = Locale.JAPAN;
 }else {
 config.locale = Locale.CHINESE;
 }
 }
 mContext.getResources().updateConfiguration(config, null);
 }
}

第四步.然后在主頁面進(jìn)行跳轉(zhuǎn)和調(diào)用,LanguageActivity就是需要改變控件語言的界面,下面會(huì)有activity_language界面代碼

override fun onClick(v: View) {
 when(v.id){
 R.id.tvChinese->{
 CommonUtil.configLanguage(this,"CHINESE")
 startActivity<LanguageActivity>()
 }
 R.id.tvEnglish->{
 CommonUtil.configLanguage(this,"ENGLISH")
 startActivity<LanguageActivity>()
 }
 R.id.tvJan->{
 CommonUtil.configLanguage(this,"JAPANESE")
 startActivity<LanguageActivity>()
 }
 }
 }

第五步:activity_language代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
 <TextView
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="@string/text1"
 android:padding="10dp"
 android:textSize="15sp"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="@string/text2"
 android:padding="10dp"
 android:textSize="15sp"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="@string/text3"
 android:padding="10dp"
 android:textSize="15sp"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="@string/text4"
 android:padding="10dp"
 android:textSize="15sp"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="@string/text5"
 android:padding="10dp"
 android:textSize="15sp"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="@string/text6"
 android:padding="10dp"
 android:textSize="15sp"
 />
</LinearLayout>

下面可以看一下整個(gè)的目錄結(jié)構(gòu)



運(yùn)行截圖:




#####代碼地址

總結(jié)

以上所述是小編給大家介紹的android 使用kotlin 實(shí)現(xiàn)點(diǎn)擊更換全局語言,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對我們網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

上一篇:Flutter 假異步的實(shí)現(xiàn)示例

欄    目:Android

下一篇:Android BottomNavigationBar底部導(dǎo)航的使用方法

本文標(biāo)題:android 使用kotlin 實(shí)現(xiàn)點(diǎn)擊更換全局語言(中日英切換)

本文地址:http://mengdiqiu.com.cn/a1/Android/9117.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有