Java 单击图像时,整个应用程序文本视图上的字体大小将增加
我必须开发一个android应用程序 在这里,我必须点击一张图片,这意味着在整个应用程序textview上自动增加字体大小。我怎样才能像iphone BBC新闻应用程序一样开发这些。请给我一些想法 编辑: 请看。这里看到第二张图片底部-A+A图片在那里…目的是要点击该图片意味着自动增加和减少整个应用程序textview fontsize。Java 单击图像时,整个应用程序文本视图上的字体大小将增加,java,android,textview,font-size,Java,Android,Textview,Font Size,我必须开发一个android应用程序 在这里,我必须点击一张图片,这意味着在整个应用程序textview上自动增加字体大小。我怎样才能像iphone BBC新闻应用程序一样开发这些。请给我一些想法 编辑: 请看。这里看到第二张图片底部-A+A图片在那里…目的是要点击该图片意味着自动增加和减少整个应用程序textview fontsize。 在android应用程序中我们该怎么做?使用imageview并实现onclicklisetner XML Onclick public void oncli
在android应用程序中我们该怎么做?使用imageview并实现onclicklisetner XML Onclick
public void onclickbtn(View v){
tv.setTextSize(20);
}
以下是查询的实现版本: 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>
我喜欢你的答案…但我需要单击该图像意味着自动增加文本大小…如缩放视图。如果我必须在zoom 50100150上拍照,则意味着其已更改,如所知。在这里,我还必须单击该图像意味着自动增加字体大小并更改整个应用程序上的文本视图字体大小。请清楚地解释您的担忧我无法理解。请看这里。这里看第二张图片底部-A+A图片在那里知道…目的是要单击该图片意味着自动增加和减少整个应用程序textview fontsize。确定。。因此,在onclick中实现int count并相应地更改fontsize。
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);}
}
}
<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>