我想知道如何更改“文本”上的语言。例如“抱歉!您的设备不支持此功能!”。我有一个英文版本的文本文件,在该版本下有新的语言版本。感谢您的帮助。
这是我的MainActivity Java代码:
package com.carlo_projekt.tvprograms;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.speech.RecognizerIntent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ImageButton speakBtn;
Button CategoriesBtn;
String viaplayPackageName;
String viafreePackageName;
String netflixPackageName;
String tvfourPlayPackageName;
String svtPlayPackageName;
String youtubePackageName;
String dplayPackageName;
String twitchPackageName;
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
speakBtn = (ImageButton) findViewById(R.id.SpeakImageBtn);
CategoriesBtn = (Button) findViewById(R.id.CategoriesBtn);
text = (TextView) findViewById(R.id.textView);
viaplayPackageName = "com.viaplay.android";
viafreePackageName = "se.viafree.android";
netflixPackageName = "com.netflix.mediaclient";
tvfourPlayPackageName = "se.tv4.tv4playtab";
svtPlayPackageName = "se.svt.android.svtplay";
youtubePackageName = "com.google.android.youtube";
dplayPackageName = "se.kanal5play";
twitchPackageName = "tv.twitch.android.app";
}
public void OpenGame(View view) {
Intent intent = new Intent(this, MoreActivity.class);
startActivity(intent);
}
public void Speak(View view)
{
Intent recognizeIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizeIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizeIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
recognizeIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Hi! Which app do you want to start?");
try {
startActivityForResult(recognizeIntent, 1);
}
catch (ActivityNotFoundException a)
{
Toast.makeText(MainActivity.this, "Sorry! Your device doesn't support this function!", Toast.LENGTH_LONG).show();
}
}
public void onActivityResult(int request_Code, int result_Code, Intent recognizeIntent)
{
super.onActivityResult(request_Code, result_Code, recognizeIntent);
switch (request_Code)
{
case 1: if(result_Code == RESULT_OK && recognizeIntent != null)
{
ArrayList<String> result = recognizeIntent.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
for(int i = 0; i<result.size(); i++)
{
result.set(i, result.get(i).toLowerCase());
if(result.get(i).compareTo("start netflix") == 0)
{
OpenApps(netflixPackageName);
}
else if(result.get(i).compareTo("start youtube") == 0)
{
OpenApps(youtubePackageName);
}
else if(result.get(i).compareTo("start viafree") == 0)
{
OpenApps(viafreePackageName);
}
else if(result.get(i).compareTo("start tvfour") == 0)
{
OpenApps(tvfourPlayPackageName);
}
else if(result.get(i).compareTo("start dplay") == 0)
{
OpenApps(dplayPackageName);
}
else if(result.get(i).compareTo("start viaplay") == 0)
{
OpenApps(viaplayPackageName);
}
else if(result.get(i).compareTo("start svtplay") == 0)
{
OpenApps(svtPlayPackageName);
}
else if(result.get(i).compareTo("start twitch") == 0)
{
OpenApps(twitchPackageName);
}
/**text.setText(result.get(i));*/
}
}
}
}
public void Swedish(View view) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(getAssets().open("language.txt")));
String lines;
while ((lines = reader.readLine()) != null)
{
if(lines.compareTo("SWEDISH:") == 0)
{
/**Det är 17 översättningar i varje språk, med mellanrum så är det 34 rader.*/
reader.read();
for(int i = 0; i < 34 && reader.read() < 34; i++)
{
}
}
text.setText(lines);
}
}
public void OpenApps(String packageName)
{
if(getPackageManager().getLaunchIntentForPackage(packageName) != null)
{
Intent tv4PlayIntent = getPackageManager().getLaunchIntentForPackage(packageName);
startActivity(tv4PlayIntent);
}
else
{
String marketAppPackageName = "market://details?id="+ packageName;
MessageBox(marketAppPackageName);
}
}
public void NetflixFunction(View view)
{
OpenApps(netflixPackageName);
}
public void ViafreeFunction(View view)
{
OpenApps(viafreePackageName);
}
public void YoutubeFunction(View view)
{
OpenApps(youtubePackageName);
}
public void Tv4PlayFunction(View view)
{
OpenApps(tvfourPlayPackageName);
}
public void LayoutsShow(View view)
{
RelativeLayout layoutShow = findViewById(R.id.LayoutShow);
if (layoutShow.getVisibility() == View.GONE) {
layoutShow.setVisibility(View.VISIBLE);
}
else if (layoutShow.getVisibility() == View.VISIBLE) {
layoutShow.setVisibility(View.GONE);
}
}
public void MessageBox(final String uriIntent)
{
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Couldn't find this app");
String messageText = "We cant find this app, do you want to download it?";
alertDialog.setMessage(messageText);
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent MarketIntent = new Intent(Intent.ACTION_VIEW);
MarketIntent.setData(Uri.parse(uriIntent));
startActivity(MarketIntent);
dialog.dismiss();
}
});
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
这是我与此应用程序其他活动的代码,这些人也将使用翻译:
package com.carlo_projekt.tvprograms;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MoreActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_more);
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
}
}
public void OpenApps(String packageName)
{
if(getPackageManager().getLaunchIntentForPackage(packageName) != null)
{
Intent tv4PlayIntent = getPackageManager().getLaunchIntentForPackage(packageName);
startActivity(tv4PlayIntent);
}
else
{
String marketAppPackageName = "market://details?id="+ packageName;
MessageBox(marketAppPackageName);
}
}
public void TwitchFunction(View view)
{
String twitchPackageName = new String("tv.twitch.android.app");
OpenApps(twitchPackageName);
}
public void SvtPlayFunction(View view)
{
String svtPlayPackageName = new String("se.svt.android.svtplay");
OpenApps(svtPlayPackageName);
}
public void ViaplayFunction(View view)
{
String viaplayPackageName = new String("com.viaplay.android");
OpenApps(viaplayPackageName);
}
public void DPlayFunction(View view)
{
String dplayPackageName = new String("se.kanal5play");
OpenApps(dplayPackageName);
}
public void NetflixFunction(View view)
{
String netflixPackageName = new String("com.netflix.mediaclient");
OpenApps(netflixPackageName);
}
public void ViafreeFunction(View view)
{
String viafreePackageName = new String("se.viafree.android");
OpenApps(viafreePackageName);
}
public void YoutubeFunction(View view)
{
String youtubePackageName = new String("com.google.android.youtube");
OpenApps(youtubePackageName);
}
public void Tv4PlayFunction(View view)
{
String tv4playPackageName = new String("se.tv4.tv4playtab");
OpenApps(tv4playPackageName);
}
public void MessageBox(final String uriIntent)
{
AlertDialog alertDialog = new AlertDialog.Builder(MoreActivity.this).create();
alertDialog.setTitle("Couldn't find this app");
String messageText = "We cant find this app, do you want to download it?";
alertDialog.setMessage(messageText);
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent MarketIntent = new Intent(Intent.ACTION_VIEW);
MarketIntent.setData(Uri.parse(uriIntent));
startActivity(MarketIntent);
dialog.dismiss();
}
});
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
这是我的MainActivity XML代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
tools:context="com.carlo_projekt.tvprograms.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<Button
android:id="@+id/CategoriesBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:background="@drawable/round_corners"
android:onClick="OpenGame"
android:text="Categories"
android:textAllCaps="false" />
<ImageButton
android:id="@+id/NetflixImageBtn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/CategoriesBtn"
android:onClick="NetflixFunction"
app:srcCompat="@drawable/netflix" />
<ImageButton
android:id="@+id/YoutubeImageBtn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignTop="@+id/NetflixImageBtn"
android:layout_toEndOf="@+id/CategoriesBtn"
android:onClick="YoutubeFunction"
app:srcCompat="@drawable/youtube" />
<ImageButton
android:id="@+id/ViafreeImageBtn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignStart="@+id/NetflixImageBtn"
android:layout_below="@+id/NetflixImageBtn"
android:layout_marginTop="52dp"
android:onClick="ViafreeFunction"
app:srcCompat="@drawable/viafree" />
<ImageButton
android:id="@+id/Tv4PlayImageBtn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignEnd="@+id/YoutubeImageBtn"
android:layout_alignTop="@+id/ViafreeImageBtn"
android:onClick="Tv4PlayFunction"
app:srcCompat="@drawable/tv4" />
<ImageButton
android:id="@+id/SpeakImageBtn"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:onClick="Speak"
app:srcCompat="@drawable/microphone" />
<ImageButton
android:id="@+id/imageButton19"
android:layout_width="40dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:onClick="Swedish"
app:srcCompat="@drawable/sweden" />
<ImageButton
android:id="@+id/imageButton24"
android:layout_width="40dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_below="@+id/imageButton19"
app:srcCompat="@drawable/great_britain" />
<ImageButton
android:id="@+id/imageButton22"
android:layout_width="40dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_below="@+id/imageButton24"
app:srcCompat="@drawable/germany" />
<ImageButton
android:id="@+id/imageButton23"
android:layout_width="40dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_below="@+id/imageButton22"
app:srcCompat="@drawable/france" />
<ImageButton
android:id="@+id/imageButton25"
android:layout_width="40dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_below="@+id/imageButton23"
app:srcCompat="@drawable/spanish" />
<TextView
android:id="@+id/textView"
android:layout_width="193dp"
android:layout_height="33dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="217dp"
android:layout_marginEnd="90dp"
android:text="TextView"
android:textColor="#ff00" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
这是我其他活动的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
tools:context="com.carlo_projekt.tvprograms.MoreActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_marginTop="45dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imageButton8"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignTop="@+id/svtPlayTabletImageBtn"
android:onClick="DPlayFunction"
app:srcCompat="@drawable/dplay" />
<ImageButton
android:id="@+id/imageButton9"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignTop="@+id/twitchTabletImageBtn"
android:onClick="ViaplayFunction"
app:srcCompat="@drawable/viaplay" />
<ImageButton
android:id="@+id/imageButton10"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignTop="@+id/TabletImageBtn"
android:onClick="SvtPlayFunction"
app:srcCompat="@drawable/svtplay" />
<ImageButton
android:id="@+id/imageButton11"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignTop="@+id/TabletImageBtn"
android:onClick="Tv4PlayFunction"
app:srcCompat="@drawable/tv4" />
<ImageButton
android:id="@+id/imageButton12"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignTop="@+id/TabletImageBtn"
app:srcCompat="@drawable/viafree" />
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_marginTop="186dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imageButton13"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignTop="@+id/svtPlayTabletImageBtn"
android:onClick="NetflixFunction"
app:srcCompat="@drawable/netflix" />
<ImageButton
android:id="@+id/imageButton14"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignTop="@+id/twitchTabletImageBtn"
android:onClick="YoutubeFunction"
app:srcCompat="@drawable/youtube" />
<ImageButton
android:id="@+id/imageButton15"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignTop="@+id/TabletImageBtn"
android:onClick="TwitchFunction"
app:srcCompat="@drawable/twitch" />
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="@+id/RealityTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="16dp"
android:textColor="#ff00"
android:layout_marginTop="16dp"
android:text="Reality:" />
<TextView
android:id="@+id/EntertainmentTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/RealityTxt"
android:layout_marginTop="156dp"
android:text="Entertainment:"
android:textColor="#ff00" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
我的文本文件如下:
ENGLISH:
Hi! Which app do you want to start?
Hi! Which app do you want to start?
Sorry! Your device doesn't support this function!
Sorry! Your device doesn't support this function!
start netflix.
Start netflix.
start youtube.
Start youtube.
start viafree
start viafree.
start tvfour.
start tvfour.
start dplay.
start dplay.
start viaplay.
start viaplay.
start svtplay.
start svtplay.
start twitch.
start twitch.
Couldn't find this app.
Couldn't find this app.
We cant find this app, do you want to download it?
We cant find this app, do you want to download it?
Yes.
Yes.
No.
No.
Categories.
Categories.
Reality.
Reality.
Entertainment.
Entertainment.
SWEDISH:
Hi! Which app do you want to start?
Hej! Vilken app vill du starta?
Sorry! Your device doesn't support this function!
Förlåt! Din telefon kan inte använda denna funktion!
start netflix.
Starta netflix.
start youtube.
Starta youtube.
start viafree.
Starta viafree.
start tvfour.
Starta tvfyra.
start dplay.
Starta dplay.
start viaplay.
Starta viaplay.
start svtplay.
Starta svtplay.
start twitch.
Starta twitch.
Couldn't find this app.
Kunde inte hitta denna app.
We cant find this app, do you want to download it?
Vi kunde inte hitta appen, vill du ladda ner den?
Yes.
Ja.
No.
Nej.
Categories.
Kategorier.
Reality.
Verklighet.
Entertainment.
Underhållning.
GERMAN:
Hi! Which app do you want to start?
Hallo! Welche App möchtest du starten?
start netflix.
Start netflix.
start youtube.
Start youtube.
start viafree.
start viafree.
start tvfour.
start tvfour.
start dplay.
start dplay.
start viaplay.
start viaplay.
start svtplay.
start svtplay.
start twitch.
start twitch.
Couldn't find this app.
Kann diese App nicht finden.
Sorry! Your device doesn't support this function!.
Es tut uns leid! Ihr Gerät unterstÜtzt diese Funktion nicht.
We cant find this app, do you want to download it?
Wir können diese App nicht finden. Möchten sie sie herunterladen?
Yes.
Ja.
No.
Nein.
Categories.
Kategorien.
Reality.
Wirklichkeit.
Entertainment.
Unterhaltung.
FRENCH:
Hi! Which app do you want to start?
Salut! quelle application voulez-vous commencer.
Sorry! Your device doesn't support this function!
Pardon! votre appareil ne supporte pas cette fonction.
start netflix.
Démarrer netflix.
start youtube.
Démarrer youtube.
start viafree.
Démarrer viafree.
start tvfour.
Démarrer tvfour.
start dplay.
Démarrer dplay.
start viaplay.
Démarrer viaplay.
start svtplay.
Démarrer svtplay.
start twitch.
Démarrer twitch.
Couldn't find this app.
N'a pas pu trouver cette application.
We cant find this app, do you want to download it?
Nous ne pouvions pas trouver cette application, voulez-vous le télécharger?
Yes.
Oui.
No.
Non.
Categories.
Catégories.
Reality.
Réalité.
Entertainment.
Divertissement.
SPANISH:
Hi! Which app do you want to start?
Hola, ¿qué aplicación quieres comenzar?
Sorry! Your device doesn't support this function!
Pedon! su dispositivo no es compatible con esta función!
start netflix.
Empezar netflix.
start youtube.
Empezar youtube.
start viafree.
Empezar viafree.
start tvfour.
Empezar tvfour.
start dplay.
Empezar dplay.
start viaplay.
Empezar viaplay.
start svtplay.
Empezar svtplay.
start twitch.
Empezar twitch.
Couldn't find this app.
No se pudo encontrar esta aplicación.
We cant find this app, do you want to download it?.
No podemos encontrar esta aplicación, ¿quieres descargarla?
Yes.
Sí.
No.
No.
Categories.
Categorías.
Reality.
Entetenimiento.
Entertainment.
Realidid.
我是堆栈溢出的新手,希望您能理解我正在尝试做的事情。