1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Device Compatibility in Android 12 App Development

Device Compatibility in Android 12 App Development

Contents

keyboard_tab

The course is part of this learning path

Multiple Language Support
Overview
Difficulty
Intermediate
Duration
51m
Students
3
Description

In this course, we look at the various components that you can use to enhance the compatibility of your app. We'll look at multi-language support, different pixel densities, and different screen sizes.

Intended Audience

This course is intended for anyone who wants to learn how to start building their own apps on Android.

Prerequisites

To get the most out of this course, you should have some basic knowledge of the fundamentals of Android.

Transcript

Well, hello everyone. So, we're going to learn now about how to support multiple languages in Android applications. You ready?

Of course, you are. So first off, Android operating systems run on millions of devices in many regions all across the world. So, of course, in these regions, many people speak many languages. So, if you develop an application in your language, well, you cannot publish your language around the world. I mean, even if you do publish, people around the world wouldn't necessarily be able to use your application. So, because of that, you need to support multiple languages in your application. Yeah, it's too difficult. I don't know, stick with me. How do you support multiple languages? That should be the question. But you're going to have to develop another application for every other language? Absolutely not. You develop one application, and in this application, you will give multiple language support. So, I'll show you how the system works. Android operating system considers English the default language.

You will develop your application in English. After that, you can support other languages, but you should be careful. And by that I just mean, you need to have that in your mind from the very beginning. You need to think that, "Yes, my app is going to support multiple languages." So, if the device language of the user is English, Android operating system shows your application in the English language. If the device of the user is, well, in another language, and your application supports this language, Android shows your application in that language. If your application does not support that user's language, Android will show your application in English again. Okay, so let me just show you an example. Let's say you develop an application in English, and you choose to support the French language. If the device language of the user is French, your application will be seen in French. But if the device language of the user is German, while your application will be seen in English because your application doesn't support German in this example.

So, now that you know that, let's go into an Android Studio and work it out. You ready? First, close the old project. I'm going to create a new project, and I'll click on 'File' in the upper left corner, click on the 'Close Project' option. So, on this page, I want to select the 'New Project' option, and after selecting 'Empty Activity' from the page it opens, I'll just click the 'Next' button. So, I'll set the name of this project as Multiple Language. You can, of course, type in any name if you really choose. Anyway, the package name will be shown here. I'm not going to change the location, and the Minimum SDK can be API 21. All right, so finally, let's start creating our project by clicking the 'Finish' button. And there's a project currently being created. It might take a minute. All right, my friends. So, we've got our project created, so let's do the design of the application.

So for this, I'll open up the activity_main.xml page, and just close the project directory. So, by clicking the eye icon here, I'll choose 'Show System UI'. So, the design area will look like a phone screen. Now, I'm going to delete the TextView component here. All right, so I have now completely emptied my design area. Now for this particular example, and, well, this whole lesson, I just want to do a simple project. So, I'll add TextView and a button to the design area. And then basically, when we click the button, the toast message will be displayed. So, I'll also write a simple expression in the TextView component, and then later on we'll learn how to add different language support, all right? So yeah, let's just do it. Cool. So, I want to add a TextView on the design area. I also want to add a button. Also, I want to change text size of this view. And doesn't the bigger size look better? Bigger isn't always better, but it does in this case. It's proportional is the point. So, I want to change the text of this TextView though.

Now, up until now, we could really only write text in this text area. For example, I can write in here Hello World, but we're not going to do it like this now, because yeah, we're supporting multiple languages. So, I need to delete this and write TextView again. So if I click here, a new window will open. In this window, I just want to click on the '+' icon, click the 'String Value'. The drama is building. So after I click the 'String Value', a new window opens. So, it's in this window that I'll define two parameters. The first one is Resource name, and I'm going to give a name to the string. So when I need this string, I'm going to call it using its name, and the name here is I'm just going to put hello. The second one is the Resource value. So, this is a string I want to write on the TextView string is Hello World. All right? I want you to notice here is the file name strings.xml. So, the strings we create here are automatically added to the strings.xml file.

Therefore, you can create any string you want directly from the strings.xml file. Why didn't I tell you that from the beginning? Stop, just click 'OK'. Now, do you see here? It writes Hello World on the TextView. But if you look at the text area, it writes in there string/hello. So if I click here again, what do you see? There's a keyword. Its name is hello and the string is Hello World. Now, I'll change the text of the button. I'll click here again, click add new resources and new 'String Value.' So when I click this button, I want it to show a toast message. And because of this, the resource name can be show toast, but in the resource name you cannot put a space. So, for this I will just write show_toast, and the resource value will Show a Toast Message. So, click 'OK'. And now you can see the Button will write Show a Toast Message. But in the text area, it writes string/show_toast. So, I can see all the strings in the string.xml file under the values folder.

So I want to open up this xml file and have a look so I can see and hear all of the string resources. The first is the name of our app. It's created automatically by Android when creating a project. Right, so, of course, the name of the string is app_name and its value is Multiple Language. The second is a string that we just created for the TextView component, and its name is hello, and the string is Hello World. The third is for the button. The name is show_toast. The string is Show a Toast Message. So, when I add new string resources, they are added here too. Right, you get that. Now, if I want to, I can add directly right in here. Both ways are the same, but I just wanted to show you that. All right, so let's go back to the design area. So when I click on this Button, I wanted this to play a toast message. I will check the Id of this Button. The Id is button. After that, I will define this button on the Kotlin side. So, I want to write in here lateinit var show : Button and in the on create method, show = findviewByID(R.id.button) I will add a click listener to this button, show.setOnClickListener.

And in curly brackets, I will write Toast.makeText() Now before we continue, I need to define another string because, well, we should create the message that we will show to the user in the toast message, namely the string in the string.xml file. So, I will open the string.xml file again. I'll open the new tag and I will write string, and select the string that gets offered to us by the code editor. Now we should define the name of this string, and let's call it toast. I will close the strings.xml tag by pressing the 'Shift' and '<' keys on the keyboard, and inside of the string tags, we should write the message. So, let's just call the message This is a toast message. Now I'm going to call this string the toast message. If you want to add multilingual support to your application, you've got to create all text expressions in a string.xml file. Otherwise, you won't be able to add multiple languages to the string if you didn't create it here. Right,

so, I want to go back to the Kotlin side. Toast method takes three parameters. The first one is applicationContext. Second one is the message. Remember, normally we write messages between the quotation marks, but this time I'm not going to write inside the quotation mark. We should call this string that we just created in the string.xml file. So for this, I will write R.string.toast. Remember, because the name of the message was toast. So, the third one is toast.LENGTH_LONG and .show. All right, so the application is ready for English. So, I want to show you. Let's run the application. Application opens when I click the button. There you go, displays a toast message. Okay, so now we can support another language. So when you go to activity_maim.xml, there is a world icon here. I just want to click on this icon and select 'Edit Translations...'

So, it opens up in a new window. So, it's in this window I can see, well, all the words that I'll need to translate. Right? And also, you can open the translations page from the strings.xml file. If you click 'Open editor', translation page opens up. So, I have four string values here. First one is application name and the others are hello, show_toast, and toast. The same four strings are here too. So I will add another language here. I'll just click the 'world' button, select the language. How about I select Turkish? And also you can see here how many languages get supported by Android. Now I will write in here the translation of every string. I will write the application name in Turkish. I'll also write the translation of Hello World. And again, I will write the translation of Show a Toast Message. And then lastly, the translation of This is a toast message.

So, when I add a new language, Android Studio adds automatically a new string.xml file. See how this file has a Turkish flag? You do know your flags, right? Well, that's another wonderful thing to Google, if you don't. So, I want to open this file, and you can see here the same string names equal translated strings in Turkish. So, when I run my application, boom, just like that, it will support the Turkish language, all right? So, let's just run the application. And there you see the application open, and the device language is English. So, because of this, my application works in English, yes. I'll change device language and select Turkish. So, just go ahead and do that now. Open up the Settings app, click 'System', click 'Language & input', and click 'Languages'. Click the 'Add a language'. Do you feel the tension building? Now from here, I just want to add Turkish. Also, I have to drag the new language that I added to the top.

Okay. So, when I select Turkish language, open my application again, everything's changed. Now my application is working in Turkish. All right. So, check this out. When I click on the button, the toast message displays in Turkish too. All right? Now, of course, if you want to, you can support all the other languages as well. The thing to keep in mind though, is this- if you want to add a different language to support your application, you need to create all the text expressions that you will use in your application in that string.xml file. All right? So, that's pretty cool. You've learned how to support multiple languages in this video. We're going to take a short break here if you need to. And I'll see you in the next video.

 

About the Author
Students
170
Courses
23
Learning Paths
1

Mehmet graduated from the Electrical & Electronics Engineering Department of the Turkish Military Academy in 2014 and then worked in the Turkish Armed Forces for four years. Later, he decided to become an instructor to share what he knew about programming with his students. He’s currently an Android instructor, is married, and has a daughter.

Covered Topics