textview 相关问题

Android小部件,向用户显示文本,并可选择允许他们编辑文本。 TextView是一个完整的文本编辑器,但基本类配置为不允许编辑

当宽度设置为“match_parent”时,无法使 TextView 中的文本居中

我对 Android SDK 比较陌生,并且正在我的 Activity UI 上使用 TextView 和其他组件。当我将宽度设置为wrap_content并使用layout_gravity时,我可以将

回答 3 投票 0

如果没有空格就断线

如果我在 Android 中添加多个文本视图,它会隐藏,当屏幕完成时我需要中断 作为一个例子,我的代码是这样的 如果我在 android 中添加多个文本视图,它会隐藏,当屏幕完成时我需要中断 作为一个例子,我的代码是这样的 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/layout5" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="last checking text"/> </LinearLayout> 结果似乎是 我需要在屏幕关闭时分解文本 并换到另一行。 这只是我以编程方式执行此操作的示例代码,因此请不要回答添加更多线性布局。 对于灵活的布局,您可以使用FlexboxLayout,您可以从Android开发者博客获取详细信息,对于开源FlexboxLayout依赖项,您可以访问Github。 如果您想以编程方式创建 TextView 并为每个 . 这是代码。首先删除布局中的所有textview。 TextView tv[] = new TextView[subCategory.length]; for (int i = 0; i < subCategory.length; i++) { tv[i] = new TextView(this); tv[i].setText(subCategory[i]); tv[i].setId(i); layout5.addView(tv[i]); tv[i].setOnClickListener(onclicklistener); } 对于听众 OnClickListener onclicklistener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == tv[0]){ //do whatever you want.... } } }; 如果您想在运行时使用文本视图的数量,您可以尝试使用 GridView as <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="match_parent" android:layout_height="match_parent" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" /> 还有 Gridview item as TextView <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text" /> 您可以在 onItemClickListener() 中执行操作 //根据位置或文本视图文本,使用 switch case 或其他方式选择操作。 GridView gridView = (GridView) findViewById(R.id.grid_view); gridView.setAdapter(yourCustomAdapterObject); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //here view is your textview switch (position) { case 0: //action break; case 1://action break; .... } } }); 如果您希望您的textView 出现多行且具有可滚动属性,则无需使用多个textView。 检查以下解决方案: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" <!--`enter code here`--> android:background="#000000" android:orientation="vertical" > <TextView android:id="@+id/textView_id" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#40000000" android:maxLines="100" android:paddingLeft="5dp" android:paddingRight="5dp" android:scrollbarThumbVertical="@android:color/transparent" android:scrollbars="vertical" android:textColor="@color/white" android:textSize="16sp" android:textStyle="bold" /> </LinearLayout> 您的活动中的以下代码: TextView txtView = (TextView) findViewById(R.id.TextView_id); txtView.setText("your text here"); txtView.setMovementMethod(new ScrollingMovementMethod());

回答 4 投票 0

Android SDK:为单词设置虚线下划线

我已经使用现有的ForegroundColorSpan 和BackgroundColorSpan 实现了一些跨越。现在,我需要通过下划线虚线选择一个单词。我用谷歌搜索并找到了一个例子:我如何......

回答 1 投票 0

如何更改 EditText 指针颜色(不是光标)

我正在尝试使EditText的指针颜色变成蓝色。 我可以使下划线和光标变成蓝色,但看起来像水滴的指针仍然是灰色的。 我用谷歌搜索了一下,但是......

回答 4 投票 0

TextView 忽略较长文本和第二行的边界。如何解决这个问题?

所以这是一个包含两个文本视图的简单 ConstraintLayout 的代码。 经典聊天气泡。当我扩展“message_body”Textview 的文本长度时,一切都会按预期工作,直到父级

回答 3 投票 0

如何以编程方式设置 TextView 的文本颜色[重复]

如何以编程方式将 TextView 的文本颜色设置为#bdbdbd?

回答 4 投票 0

如何在运行时更改 TextView 的样式

我有一个Android应用程序,当用户点击TextView时,我想应用定义的样式。 我想找到一个 textview.setStyle() 但它不存在。我试过 textview.setTextAppea...

回答 8 投票 0

Android TextView Marquee 不起作用

选框不适用于我的 TextView 请检查下面的代码 TextView 的 XML 代码 选框不适用于我的 TextView 请检查下面的代码 XML 代码 TextView <TextView android:id="@+id/mtextcash" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="30dp" android:ellipsize="marquee" android:fadingEdge="horizontal" android:gravity="center" android:marqueeRepeatLimit="marquee_forever" android:maxLength="5" android:scrollHorizontally="true" android:scrollbars="horizontal" android:singleLine="true" android:text="Simple application that shows how to use marquee, with a long text" android:textColor="@color/white" android:textColorHint="@color/white" android:textSize="25dp" /> 在 Activity OnCreate 中 TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash); inputAvailableCash.setSelected(true); 提前致谢 由于文本很长,并且只有在单行中编写文本时您的代码才能工作。要么添加 android:singleline="true" 在 xml 中或将您的 java 代码更改为。 TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash); inputAvailableCash.setSelected(true); inputAvailableCash.setSingleLine(true); 这肯定对你有用。 一旦尝试将这些参数放入您的 TextView - 它就有效 android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:focusable="true" android:focusableInTouchMode="true" 而且你还需要setSelected(true): my_TextView.setSelected(true); 在 TextView 上运行选取框的最低代码是 <TextView . . android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" /> 也不要忘记如下设置选择 textview.setSelected(true); 在xml文件中添加此属性 android:focusable="true" android:focusableInTouchMode="true" 对于选取框效果,宽度应始终为“match_parent”或静态(如 200dp...等)。并以编程方式将其设置为 setSelected true,就像您已经完成的那样,然后只需将其宽度设置为 xml 中的 match_parent 即可。 编辑的xml: <TextView android:id="@+id/mtextcash" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="30dp" android:ellipsize="marquee" android:fadingEdge="horizontal" android:gravity="center" android:marqueeRepeatLimit="marquee_forever" android:maxLength="5" android:scrollHorizontally="true" android:scrollbars="horizontal" android:singleLine="true" android:text="Simple application that shows how to use marquee, with a long text" android:textColor="@color/white" android:textColorHint="@color/white" android:textSize="25dp" /> 如果通过执行 match_parent 它会影响您的设计,那么您必须通过固定其宽度或其他方式来管理它。 根据您使用的 xml 代码 android:maxLength="5" 意味着仅输入 5 个字符,因此您可以将其宽度固定为 50dp 或任何其他静态大小。 嘿,检查此代码,但是当您的文本大小(即长度较长)时,选框工作。它在我这边工作。:) <TextView android:id="@+id/mywidget" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:singleLine="true" android:textColor="#2086CA" android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." android:textAppearance="?android:attr/textAppearanceSmall" /> 希望这有帮助。:) <TextView android:id="@+id/mtextcash" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:ellipsize="marquee" android:gravity="center" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLine="true" android:text="Simple application that shows how to use marquee, with a long text" android:textColor="@color/white" android:textColorHint="@color/white" android:textSize="25dp" /> 我错误地设置了 android:maxLines="1" 而不是使用 android:singleLine="true"。切换后,一切都按预期运行。

回答 8 投票 0

如何防止TextView中显示null?

对于 Android 来说非常陌生,老实说我对此感到困惑。 因此,我让 MainActivity 从第二个活动 CallAnActivity 接收一些字符串。 我已经决定将琴弦传回给...

回答 3 投票 0

如何获取TextView的行距?

Android中有没有办法获取TextView的行距?我尝试找到 TextView 的 Paint 的 fontMetrics 并执行以下操作: tv1.getPaint().getFontMetrics(pfm); 浮动字体顶部 = pfm.t...

回答 3 投票 0

如何在 Android 中显示彼此下方可变长度的项目符号点

我想在 Android 弹出窗口(使用 Java)中添加一个包含可变大小(行号)的项目符号点的列表,以便项目符号直接从彼此下方开始。例如我有...

回答 1 投票 0

TextView 中的 HTML 格式

我的字符串资源 xml 文件中有以下内容。 世界你好,ProDroid_A...

回答 1 投票 0

如何在约束布局中实现动态textview调整大小?

我在约束布局中有两个文本视图,它们水平相邻: 我在约束布局中有两个文本视图,它们水平相邻: <?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="wrap_content" android:orientation="horizontal" android:paddingVertical="12dp"> <TextView android:id="@+id/textViewLeft" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="2" app:layout_constrainedWidth="true" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@id/textViewRight" app:layout_constraintHorizontal_chainStyle="spread_inside" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/textViewRight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:ellipsize="end" android:maxLines="2" android:singleLine="false" app:layout_constrainedWidth="true" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/textViewLeft" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> 当我为第一个文本视图设置长文本,为第二个文本视图设置短文本时,一切正常,第一个文本视图中的文本换行到另一行并被省略。 但是当我在第二个文本视图中制作长文本时,它会破坏第一个文本视图 出了什么问题以及如何解决? 试试这个,我在 TextView 之间插入视图并将其对齐到中心。并相应地设置约束。您也可以使用指南/障碍来实现这一点。 <?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" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="12dp"> <TextView android:id="@+id/textViewLeft" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="2" app:layout_constrainedWidth="true" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@id/divider" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <View android:id="@+id/divider" android:layout_width="1dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="@id/textViewLeft" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/textViewRight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:ellipsize="end" android:maxLines="2" android:singleLine="false" app:layout_constrainedWidth="true" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/divider" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>

回答 1 投票 0

在Android中使用Html.fromHtml()突出显示文本颜色?

我正在开发一个应用程序,其中会有一个搜索屏幕 用户可以在其中搜索特定关键字,并且该关键字应该是 突出显示。我找到了 Html.fromHtml 方法。 但我...

回答 11 投票 0

在 TextView 数组中,仅显示最后一个 TextView

我正在尝试显示 TextView 数组,但只显示最后一个 TextView。我已经检查过根据 i 值移动约束边距,发现它们不在一个 a 之上...

回答 2 投票 0

Android:如何在 Kotlin 中获取自动调整大小的 TextView 的实际文本大小?

有时需要为多个自动调整大小的 TextView 设置相同的 textSize。例如,“数字输入”EditText 旁边的“单位”TextView。 然而,目前

回答 1 投票 0

Android XML 中 Textview 脱离父布局

我在保持文本视图可见并位于父布局的中心方面遇到一些问题 这是我想要的预期输出(这是图像,而不是 ui 布局本身) 但因为我不使用...

回答 1 投票 0

TextView 和 WebView 中的自定义字体问题

使用阿拉伯语或波斯语字体时,TextView 和 WebView 中的英文文本存在问题,下图是 TextView 中的波斯语和英文文本的示例(头部有 2 个视图...

回答 1 投票 0

“在视图更新期间修改状态,这将导致未定义的行为”使用表单内的 tabview 切换屏幕时控制台警告

这是我使用 SwiftUI 的第一个项目,它就像一个家庭库存跟踪器,我遇到了一个我不知道如何解决的问题。我的代码运行且功能正常,但是当按下按钮时...

回答 1 投票 0

Textview 文本在达到 2 行时会下降

我有以下代码。 我有以下代码。 <LinearLayout android:layout_marginStart="@dimen/space_10" android:layout_marginEnd="@dimen/space_10" android:layout_width="match_parent" android:layout_height="wrap_content" android:weightSum="3.2" android:orientation="horizontal" > <TextView android:id="@+id/tvDonate" android:fontFamily="@font/tajawal_medium" android:textSize="@dimen/font_size_14" android:textColor="@color/colorPrimary" android:background="@drawable/background_yellow_rounded_corner" android:gravity="center" android:layout_weight="1" android:text="@string/text_donation_title" android:layout_width="0dp" android:layout_height="@dimen/space_48"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.1" /> <TextView android:id="@+id/tvRecurring" android:fontFamily="@font/tajawal_medium" android:textSize="@dimen/font_size_14" android:textColor="@color/white" android:background="@drawable/background_darkergreen_rounded_corner" android:gravity="center" android:layout_weight="1" android:text="@string/recurring_donation" android:layout_width="0dp" android:layout_height="@dimen/space_48"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.1" /> <TextView android:id="@+id/tvAddToCart" android:fontFamily="@font/tajawal_medium" android:textSize="@dimen/font_size_14" android:textColor="@color/colorPrimary" android:background="@drawable/greenborder_bg_10" android:gravity="center" android:layout_weight="1" android:text="@string/addToCart" android:layout_width="0dp" android:layout_height="@dimen/space_48"/> </LinearLayout> 第二个文本视图文本向下移动。 知道为什么会发生这种情况吗? 注意:如果文本是 1 行,一切都很好... 将文本视图高度设置为 match_parent android:layout_height="match_parent"

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.