[英]How do I change the color and lettertype in my fragments first code?
I am busy to build something in my first android app "a questionnaire overview".我正忙于在我的第一个 android 应用程序“调查问卷概述”中构建一些东西。 and I need just to know how can I change the color, letter type and size of the text view.
我只需要知道如何更改文本视图的颜色、字母类型和大小。
can someone help me to which code.有人可以帮我找到哪个代码。 I am very appreciated thanks.
非常感谢。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FirstFragment">
<TextView
android:id="@+id/textView"
android:layout_width="68dp"
android:layout_height="24dp"
android:text="Overzicht"
tools:layout_editor_absoluteX="33dp"
tools:layout_editor_absoluteY="83dp"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/textView"
android:layout_width="68dp"
android:layout_height="24dp"
android:text="Overzicht"
tools:layout_editor_absoluteX="33dp"
tools:layout_editor_absoluteY="83dp"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/textView2"
android:layout_width="306dp"
android:layout_height="85dp"
android:text="Hieronder ziet u een overzicht van de antwoorden die u gegeven heeft. Controleer de antwoorden en pas deze waar nodig aan. Als u de vragenlijst naar wens heeft ingevuld kunt u op Verzenden klikken."
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="33dp"
tools:layout_editor_absoluteY="141dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Color change:颜色变化:
android:textColor="#FFFFFF"
See color codes here: link在此处查看颜色代码:链接
Font (Letter type) change:字体(字母类型)更改:
android:fontFamily="name of the font family"
See font families here: link在此处查看字体系列: 链接
Letter size change:字母大小变化:
android:textSize="xxdp"
xx is the size of the font. xx 是字体的大小。
You can always refer to this site for guides and documentation: Android dev您可以随时参考此站点以获取指南和文档: Android dev
if you want change programmatically using java in your onCreateView method inside fragment use:如果您想在片段内的onCreateView方法中使用 java 以编程方式更改,请使用:
View view = inflater.inflate(R.layout.YOUR_FRAGMENT_VIEW, container, false);
TextView tv;
tv= findViewById(R.id.textView);
Typeface font;
now if you want change font , first you open a asset folder and inside that add the fontName.ttf in onCreateView method inside your fragment add bellow code:现在如果你想改变字体,首先你打开一个资产文件夹并在里面添加 fontName.ttf in onCreateView方法在你的片段中添加波纹管代码:
font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/fontName.ttf ");
tv.setTypeface(font);
if you want change TextView color如果你想改变 TextView 颜色
tv.setTextColor(Color.RED);
if you want change TextView size如果你想改变 TextView 尺寸
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,14);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.