【问题标题】:font size will be increase on whole app textview when click image单击图像时,整个应用程序文本视图的字体大小将增加
【发布时间】:2013-02-10 11:39:32
【问题描述】:

我必须开发一个 android 应用程序。

在这里我必须单击一个图像意味着自动增加整个应用程序 textview 的字体大小。我如何开发这些像 iphone BBC 新闻应用程序。请给我一些想法???

编辑:

请看here.here 看第二张图片底部-A + A image is there...目的是必须单击该图像意味着自动增加和减少整个应用程序的textview字体大小。 我们如何在 android app 中做 ???

【问题讨论】:

    标签: java android textview font-size


    【解决方案1】:

    使用imageview并实现onclicklisetner

    XML

    <TextView
            android:id="@+id/firsttv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="serif"
            android:gravity="center"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="20dip"
            android:text="@string/prompt" />
    
    <ImageButton
                android:id="@+id/imagebtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:background="@android:color/transparent"
                android:contentDescription="@string/description"
                android:onClick="onclickbtn"
                />
    

    Java

    注册:

    TextView tv;
    
    tv=(TextView)findViewById(R.id.firsttv);
    

    点击

    public void onclickbtn(View v){
    
    tv.setTextSize(20);
    
            }
    

    【讨论】:

    • 我喜欢您的回答...但我需要单击该图像意味着自动增加文本大小...例如缩放视图。如果我必须在缩放时拍照 50,100,150 意味着它已经改变了。 .这里我还必须单击该图像意味着自动增加字体大小并更改整个应用程序的 textview 字体大小。
    • 请解释清楚我无法理解的问题。
    • please see here.here see the 2nd image bottom -A +A image is there know...目的是必须单击该图像意味着自动增加和减少整个应用程序的textview字体大小。@987654321 @
    • 好的.. 所以在你的 onclick 中实现 int count 并相应地更改字体大小。
    【解决方案2】:

    这是您的查询的实施版本:

    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>
    

    【讨论】:

      猜你喜欢
      • 2014-04-06
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 2014-08-06
      • 2022-12-03
      相关资源
      最近更新 更多