Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中使用style.xml设置填充和文本类型面_Android - Fatal编程技术网

如何在android中使用style.xml设置填充和文本类型面

如何在android中使用style.xml设置填充和文本类型面,android,Android,我希望使用需要在style.xml中定义的样式设置填充 请建议我们可以设置填充和字体粗体样式,我们可以在课堂上阅读该样式假设您将其设置为文本视图,您只需创建如下样式 24dp 24dp 24dp 24dp 大胆的 和这个一样容易分配 style=“@style/TextViewStyle” 编辑:因为您没有XML格式的文本视图,所以这是除此之外的唯一方法 val textView=textView(yourContext,null,0,R.style.your_-style); 我可能误解

我希望使用需要在style.xml中定义的样式设置填充
请建议我们可以设置填充和字体粗体样式,我们可以在课堂上阅读该样式

假设您将其设置为文本视图,您只需创建如下样式


24dp
24dp
24dp
24dp
大胆的
和这个一样容易分配

style=“@style/TextViewStyle”
编辑:因为您没有XML格式的文本视图,所以这是除此之外的唯一方法

val textView=textView(yourContext,null,0,R.style.your_-style);

我可能误解了你的意思。你有一个XML,其中有一个TextView correct@AmritaThakurNO,我们没有这样定义的XML val TextView=TextView(context)@AmritaThakur,我正在更新同样的答案。
 val textView = TextView(context)
        textView.text = "This is my message for title text  "
        context?.let {
            textView.setPadding(
                convertDpToPx(it, 24f),
                convertDpToPx(it, 24f),
                convertDpToPx(it, 24f),
                0
            )
            textView.setTypeface(textView.typeface, Typeface.BOLD);
        }

private fun convertDpToPx(context: Context, dp: Float): Int {
        return (dp * context.resources.displayMetrics.density).toInt()
    }