クエリの実装バージョンは次のとおりです。
Javaコード:
package com.anurag.increasefont;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv;Button b1,b2;int count=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.tv1);
b1=(Button)findViewById(R.id.b1);
b2=(Button)findViewById(R.id.b2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void increase(View inc){
count++;
if(count==1){tv.setTextSize(20); }
else if(count==2){tv.setTextSize(30);}
else if (count>=3) {count=3;tv.setTextSize(40);}
}
public void decrease(View dec){
count--;
if(count<=0){tv.setTextSize(12);count=0;}
if(count==1){tv.setTextSize(20);}
else if(count==2){tv.setTextSize(30);}
else if (count==3) {tv.setTextSize(40);}
}
}
XMLコード:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
tools:context=".MainActivity" >
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="This is sample text, i will increase and decrease the font size when user clicks on A+ and A_ buttons provided below. I can also use imageview or image button instead of Buttons to perform the same" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/textView1"
android:onClick="decrease"
android:text="Decrease" />
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="increase"
android:text="Increase" />
</RelativeLayout>