I ask for help, I am trying to build a simple program that contains a text field (Edittext) and two buttons. The idea is to write any text in my text field and then if I click the first button I want my text to change to italic and if I click the second button the text changes to Bold.
I ask for help there.
I'll post the codes:
<EditText
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/et1"/>
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/italico"
android:text="Itálico"
/>
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/negrito"
android:text="Negrito"/>
And the java code:
public class MainActivity extends AppCompatActivity {
EditText t1;
Button b1, b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1=(EditText)findViewById(R.id.texto);
b1=(Button)findViewById(R.id.italico);
b2=(Button)findViewById(R.id.negrito);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Preciso tomar o texto no campo t1 e mudá lo para itálico
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Preciso tomar o texto no campo t1 e mudá lo para Negrito
}
});
}}
Now I want to build a program that contains 3 text fields (Edittext) with the following text Id1, text2 and text3 respectively and a Button with id Take, where the program asks to type any two texts in the fields text1 and text2 and clicking the Take button searches for the texts that are in the text1 and text2 fields and at the same time write in the text field3 but I need the text in the text field3 to be printed in bold and the field text text2 in italics.
See the codes:
<EditText
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/texto1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/texto2"/>
<EditText
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/texto3"/>
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/Take"
android:text="Take"/>
and the Java code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1=(EditText)findViewById(R.id.texto1);
t2=(EditText)findViewById(R.id.texto1);
t3=(EditText)findViewById(R.id.texto1);
b1=(Button)findViewById(R.id.Take);
final Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD); //negrito
final Typeface italicTypeface = Typeface.defaultFromStyle(Typeface.ITALIC); //itálico
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}