I am trying to make a customisation app for wooden signs. When the user clicks say on a 10 x10 size sign i want the edit text box to change size to demonstrate what they have done. Can this be done on android studio? This is my code so far, I think what i have done is changed the size of the text but it crashes when the button is clicked so i don't know. Java File:
public class Letters extends AppCompatActivity {
int txtSize = 14;
EditText Wood;
Button bSize, bSize1, bSize2, bSize3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_letters);
Button bSize = (Button) findViewById(R.id.bSize);
Button bSize1 = (Button) findViewById(R.id.bSize1);
Button bSize2 = (Button) findViewById(R.id.bSize2);
Button bSize3 = (Button) findViewById(R.id.bSize3);
bSize.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (Wood.getTextSize() == 15) {
txtSize--;
Wood.setTextSize(txtSize);
} else {
txtSize += 0;
Wood.setTextSize(txtSize);
}
}
});
bSize1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (Wood.getTextSize() == 16) {
txtSize--;
Wood.setTextSize(txtSize);
} else {
txtSize += 0;
Wood.setTextSize(txtSize);
}
}
});
bSize2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (Wood.getTextSize() == 17) {
txtSize--;
Wood.setTextSize(txtSize);
} else {
txtSize += 0;
Wood.setTextSize(txtSize);
}
}
});
bSize3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (Wood.getTextSize() == 18) {
txtSize--;
Wood.setTextSize(txtSize);
} else {
txtSize += 0;
Wood.setTextSize(txtSize);
}
}
});
}
}
xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_height="match_parent"
android:padding="60dp"
android:layout_width="match_parent"
android:weightSum="1">
<Button
android:id="@+id/bSize"
android:text="15 x 10 cm "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="bSize" />
<Button
android:id="@+id/bSize1"
android:text="20 x 15 cm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="bSize1" />
<Button
android:id="@+id/bSize2"
android:text="30 x 7 cm"
android:layout_width="103dp"
android:layout_height="61dp"
android:onClick="bSize2" />
<Button
android:id="@+id/bSize3"
android:text="30 x 20 cm"
android:layout_width="0dp"
android:layout_marginBottom="20dp"
android:layout_height="160dp"
android:onClick="bSize3"
android:layout_gravity="center_vertical" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/Wood"
android:textSize="40dp"
android:layout_alignTop="@+id/button3"
android:layout_centerHorizontal="true"
android:background="#795548"
android:hint="Choose Letters.."/>
</LinearLayout>