麻烦更改字体大小 [英] Trouble with changing the font size

查看:140
本文介绍了麻烦更改字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
             我试图让我的用户通过操作栏中按下一个按钮来改变我的活动的EditText上的字体大小(增加或减少)。我已经得到的字体大小增加工作,但由于某种原因,字体大小减小按钮使字体大小增加。

HI everyone, I am trying to allow my user to change the font size(increase or decrease) in my activity's EditText by pushing a button in the action bar. I have gotten the font size increase to work but for some reason the font size decrease button makes the font size increase as well.

我附上(我认为是)有关code。让我知道如果你需要看到code的电气特性的击打。

I am attaching (what I think is) the relevant code. Let me know if you need to see anyother buts of code.

public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
        case R.id.TEXT_UP:
            doTextUp();
            break;
        case R.id.TEXT_DOWN:
            doTextDown();
            break;
         default:
                return super.onOptionsItemSelected(item);
            }
            return false;
        }




private void doTextDown() {
    mBodyText = (EditText) findViewById(R.id.body);
    float Textsize = mBodyText.getTextSize() - 1;
    mBodyText.setTextSize(Textsize);
    Toast.makeText(getApplicationContext(), "in the text down",Toast.LENGTH_SHORT).show();

}

private void doTextUp() {
    mBodyText = (EditText) findViewById(R.id.body);
    float Textsize = mBodyText.getTextSize() + 1;
    mBodyText.setTextSize(Textsize);
    Toast.makeText(getApplicationContext(), "in the text up",Toast.LENGTH_SHORT).show();

}

结果任何建议?

推荐答案

尝试都更改为:

mBodyText.setTextSize(TypedValue.COMPLEX_UNIT_PX, Textsize);

getTextSize()返回像素大小,但 setTextSize(浮点大小)间$ P $点作为一个缩放像素(SP)单元。要指定你需要使用像素 setTextSize(INT单元,浮点大小)

getTextSize() returns the size in pixels but setTextSize(float size) interprets it as a "scaled pixel" (sp) unit. To specify pixels you need to use setTextSize (int unit, float size)

http://developer.android.com/参考/安卓/空间/ TextView.html#getTextSize()
http://developer.android.com/reference/android/widget/TextView.html#setTextSize(float)

这篇关于麻烦更改字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆