asinandroidstudio_layout:
<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/name_label"
/>
<EditText
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/see_message_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/see_message"
/>
<TextView
android:id="@+id/show_message_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="@string/hello_message"
android:textStyle="bold"
android:textSize="24dp"
android:visibility="invisible"
/>
</LinearLayout>
as in android studio_layout_ code main:
package com.example.pc_vicl.myapplication;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.app.Activity;
import java.awt.font.TextAttribute;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText nameEditText=(EditText) findViewById(R.id.name_edit_text);
seeMessageButton = (Button) findViewById(R.id.see_message_button);
final TextView showMessageText = (TextView) findViewById(R.id.show_message_text);
seeMessageButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick (View view){
String name=nameEditText.getEditableText().toString();
showMessageText.setText(getString(R.string.hello_message, name));
showMessageText.setVisibility(View.VISIBLE);
}
});
}
}
as in android studio_layout_strings:
<resources>
<string name="name_label">Nome:</string>
<string name="see_message">Ver mensagem</string>
<string name="app_name">Ola Mundo </string>
<string name="hello_message">Olá, %1$!</string>
</resources>