简体   繁体   English

用按钮更改textview的文本大小

[英]Change textsize of textview with button

I want to implement a feature that allows user to change the textSize of a textView in another view inside the app, 我想实现一项功能,允许用户在应用程序内的另一个视图中更改textView的textSize,

So I have a button with its "onClick" property set to: 所以我有一个按钮的“ onClick”属性设置为:

Class mainActivity
    public void increaseFont(View view)
    {
        MainViewPager.changeTextViewTextSize(mTextSize);
    }

Class MainViewPager

    static public void changeTextViewTextSize(int aTextSize)
    {
        View detailView = (View) LayoutInflater.from(mContext).inflate(R.layout.details, null);
        TextView description = (TextView) detailView.findViewById(R.id.story_description);
        description.setTextSize(aTextSize);
    }

QUESTIONS is the textSize can't be changed when clicking the button. 问题是单击按钮时无法更改textSize。 So how to? 那怎么办?

The text size can changed at run time of course. 当然,文本大小可以在运行时更改。 You issue is related to the method changeTextViewTextSize . 您所发布的与方法changeTextViewTextSize Using the inflater you are creating a new instance of R.layout.details , and through it, you are looking for the TextView you want to change the text size. 使用充气机,您将创建一个R.layout.details的新实例,并通过它查找要更改文本大小的TextView。 But that layout is not at screen. 但是这种布局不在屏幕上。 It is not what you are seeing. 这不是您所看到的。

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

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