简体   繁体   English

如何更改片段优先代码中的颜色和字母类型?

[英]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.

相关问题 我第一次访问“活动”时,“片段”中的菜单项不会根据代码更改 - Menuitems in my Fragments do not change according to the code for the first time I access Activity 如何避免片段代码重复? - How do I avoid code duplication for fragments? 如何更改 Android 应用程序中时间选择器的颜色? - How do I change the color of the timepicker in my Android app? 如何在 Android 中更改 canvas 上的油漆颜色/厚度? - How do I change the color/thickness of my paint on a canvas in Android? 如何更改我的 Android 应用程序列的背景颜色 - How do I change the background color for a column of my Android app 我如何将两个活动从我的代码转换为两个片段 - How do i convert the two activities from my code to two Fragments 如何更改Java按钮的颜色? - How do I change the color of my Java button? 发生配置更改时,如何不重置片段? - How do I not reset my fragments when configuration changes happen? 如何更改JFrame的背景颜色(我是大一学生) - How to change the background color of my JFrame (I'm a first year university student) 如何为ViewPager提供许多片段并避免错误代码? - How do I supply many Fragments to ViewPager and avoid bad code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM