-2

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

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

编辑:

请看这里。这里看第二张图片底部-A + A图片在那里...目的是必须单击该图片意味着自动增加和减少整个应用程序的textview字体大小。我们怎么能在 android 应用程序中做?

4

2 回答 2

0

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

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>
于 2013-02-25T14:31:24.530 回答
0

使用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"
            />

爪哇

登记:

TextView tv;

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

点击

public void onclickbtn(View v){

tv.setTextSize(20);

        }
于 2013-02-25T10:51:46.797 回答