简体   繁体   English

Android WebView中的TextView增加和减少

[英]textview increase and decrease in android webview

I have to develop one Android application. 我必须开发一个Android应用程序。 Here I have to increase and decrease the TextView text size. 在这里,我必须增加和减少TextView文本大小。

I have to click two ImageView (positive and negative). 我必须单击两个ImageView (正负)。

First , I have to click the positive image which means I have to increase the text size by 3 times afterthat have to disable the positive image. 首先 ,我必须单击图像,这意味着我必须将文本大小增加3倍,然后才能禁用正图像。 Secondly , I have to click the negative image which means I have to decrease the text size by 5 times afterthat have to disable the negative image. 其次 ,我必须单击负片图像,这意味着我必须将文本大小减小5倍,然后才能禁用负片图像。

Third , now I have to click the negative image directly without click the positive image which means I have to decrease the text size by 2 times and the negative image is disabled. 第三 ,现在我必须直接单击负片图像而不单击正片图像,这意味着我必须将文本大小减小2倍,并且负片图像被禁用。 How can I develop these? 如何开发这些?

My current situation is looking like : 我目前的情况看起来像:

First , I have to click positive image means increasing the value 3 times. 首先 ,我必须单击图像表示将值增加3倍。 The image isn't disabled. 该图像未禁用。 Please tell me how I can disable the positve image. 请告诉我如何禁用正片图像。 Second I have to click the negative image which means decreasing the text size 5 times. 其次,我必须单击图像,这意味着将文本大小减小5倍。

Third I have to click the negative image directly without click the positive image which means the text size is not decreasing? 第三,我必须直接单击负图像而不单击正图像,这意味着文本大小没有减少吗? How can I resolve these problems? 我该如何解决这些问题?

int text_size=16;int text_max;
   int text_min=12;
String fullcontent = in.getStringExtra("FullContent");
content.loadDataWithBaseURL(null,fullcontent, "text/html", "UTF-8",null);
positive = (ImageView) findViewById(R.id.imageView3);
positive.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
       if (text_size < 22) {
           content.getSettings().setDefaultFontSize(text_size += 1);
         text_max=  text_size++;
            j = text_max;      
     if (j == text_max)
    {
        positive = (ImageView) findViewById(R.id.imageView3);
        positive.setEnabled(false);
    }   
         }
   }  
});   

negative = (ImageView) findViewById(R.id.imageView4);
negative.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
      if (j > 12)
  {
      //Description.FontSize -= 2;
   content.getSettings().setDefaultFontSize(j -= 1);
   int k=   j--;
   text_min = k;
      if (text_size == j)
      {
          negative = (ImageView) findViewById(R.id.imageView4);
          negative.setEnabled(false);
      }  
    }
      }  
});   

EDIT: 编辑:

Initially i have declared the text_default,text_max,text_min size like : 最初我已经声明了text_default,text_max,text_min的大小,例如:

int text_size=16;
int text_max=22;
int text_min=10;

I have to write the condition for increase the fontsize maximum while clikcing positive image: 我必须写条件以增加最大字体大小,同时使正像对齐:

 positive = (ImageView) findViewById(R.id.imageView3);
 positive.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
 if (text_size < 22)
 {
    content.getSettings().setDefaultFontSize(text_size += 1);
    text_max=  text_size++;
    j = text_max;
    }} });

I have wrote the condition for decrease the textSize while clicking negative image: 我写了在单击负图像时减小textSize的条件:

negative = (ImageView) findViewById(R.id.imageView4);
negative.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
 if (j > 10)
  {
   content.getSettings().setDefaultFontSize(j -= 1);
   int k=   j--;
   text_min = k;
    }} });

Now i have to run the application and directly click the positive image means the textsize will be increase 3 times.after that i have to click the negative image means the textsize will be decrease the 5 times.its worked well... 现在我必须运行该应用程序并直接单击正图像意味着文本大小将增加3倍。之后,我必须单击负图像意味着文本大小将减小5倍。它运作良好...

But i have to run the application and directly click the negative image means the textsize will be decrease the textsize 3 times like bbc news reader application(A+,A- functionality). 但是我必须运行该应用程序,然后直接单击负图像,这意味着textsize会像bbc新闻阅读器应用程序(A +,A-功能)一样减小3倍。

How can i do ??? 我能怎么做 ??? please give me some idea to develop ??? 请给我一些想法发展???

Try something like this : 尝试这样的事情:

At the start get a handle to the textView's textSize. 首先,获取textView的textSize的句柄。

float textSize = textView.getTextSize();
if (//Check if first time) {

    textView.setTextSize(textView.getTextSize() * 3f);

or 要么

    textView.setTextSize(textView.getTextSize() / 3f);
}
else {
    textView.setTextSize(textView.getTextSize() * 5f);

or 要么

    textView.setTextSize(textView.getTextSize() / 5f);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM