【问题标题】:Readjust text inside an EditText (android)重新调整 EditText (android) 中的文本
【发布时间】:2015-09-04 19:14:10
【问题描述】:

是否可以在文本太长时动态更改 EditText 的文本大小并重新调整以适应范围?

【问题讨论】:

    标签: java android text android-edittext bounds


    【解决方案1】:

    我相信你应该创建一个自定义的 TextView。查看@speedplane 解决方案: How to adjust text font size to fit textview

    【讨论】:

    • 这是我想做的事情......但我想调整editText中的文本,而不是文本视图
    【解决方案2】:
    EditText editText = (EditText) findViewById(R.id.editText);
    editText.addTextChangedListener(new TextWatcher()
    {
        public void afterTextChanged(Editable s) {}
        public void beforeTextChanged(CharSequence s, int start, int count, int after){}
        public void onTextChanged(CharSequence s, int start, int before, int count)
        {
            if (editText.getText().toString().length() > 15)
            {
                editText.setTextSize(10)
            }
    });
    

    我没有对此进行测试,但通常应该可以。

    【讨论】:

    • 但在某些设备(屏幕较大)中,editText 可以包含超过 15 个字符.....相反,较小屏幕设备可以包含少于 15 个字符
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-03
    • 2012-11-24
    • 2014-12-19
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多