Android上的默认文字大小是多少? [英] What is the default text size on Android?
问题描述
我混合使用Buttons和自己的View,在其中使用Paint.setTextSize()设置文本大小.我希望文本大小看起来像按钮上的文本一样.现在,我当然可以将按钮的文本大小设置为18sp,并在我看来使用18.但是,为了更好地集成,我只是想知道按钮的正常"文本大小是多少.根据我的测试,它应该类似于12sp,但是我还没有找到关于此的任何文档.
I have a mixture of Buttons and an own View, where I set my text size using Paint.setTextSize(). I want the text size to look the same like the text on the Button. Now, I can of course set the text size of the button to e.g. 18sp, and use 18 in my view. But for a better integration, I simply would like to know, what text size is "normal" for buttons. From my test, it should be something like 12sp, but I have not found any documentation on this.
保留默认大小会使视图中的文本太小.
Leaving the default sizes leaves way too small text on the view.
也许我应该使用另一种方法来解决这个问题?
Maybe I should use still another approach to this issue?
推荐答案
这将返回按钮上文本的默认大小(以像素为单位).
This will return default size of text on button in pixels.
val size = Button(this).textSize
float size = new Button(this).getTextSize();
这篇关于Android上的默认文字大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!