android-button 相关问题

按钮由文本或图标(或文本和图标两者)组成,用于传达用户触摸时发生的操作。此标记用于解决Android平台上的按钮问题。

切换列表视图行中 2 个按钮的按钮状态

我有一个活动显示有 2 行的列表视图。每行都有一个问题,从数据库中提取,每行有 2 个按钮,一个“是”按钮和一个“否”按钮。 我正在尝试设置按下的位置...

回答 1 投票 0

Kotlin:文本从 RecyclerView 中的按钮消失

我设置了一个包含按钮列表的 RecyclerView。列表的长度和每个按钮的文本应来自数据库查询的结果(我在其中查找数据库中保存的所有食谱)。

回答 1 投票 0

需要点击后退箭头两次才能返回到上一个活动,如何防止它

我有一个活动 A,当我单击活动 A 中的一个按钮并进入另一个活动 B 时,当我单击活动 B 中的后退箭头返回 A 时,它会进入同一个活动...

回答 1 投票 0

以编程方式使用 ConstraintSet 将 Button 添加到 ConstrainLayout

大家好。 我尝试以编程方式将按钮添加到 ConstraintLayout 并将 ConstraintSet 设置为此类按钮。 当我尝试从布局中关闭约束集时,问题就出现了...

回答 1 投票 0

自 Android Studio 4.1 起,Android 后台 Drawable 无法在按钮中工作

我发现从 Android Studio 4.1 开始,我无法通过在其 android:background 上设置颜色来更改 Button 的背景颜色,只是没有效果。并且自定义 Drawable 也无法正常工作。 我的

回答 6 投票 0

带有复选框的Android ListView:如何捕获选中的项目?

我必须用复选框做一个ListView,然后在用户按下按钮时显示选中和未选中的项目。问题是我不知道该怎么做,我设法显示 ListView 机智...

回答 1 投票 0

为什么我无法在 Button( ) 的 onClick ={ } 中使用 Text( ) ?

我是 Kotlin Jetpack Compose 库的纯粹初学者,我正在制作一个简单的 UI 来练习。我 制作了一个按钮,我想在有人点击代码时显示文本,但我得到了一个

回答 1 投票 0

如何使用jetpack compose创建圆形轮廓按钮

我正在尝试创建一个圆形 OutlinedButton,其中心有一个图标,没有文本。 OutlinedButton(onClick = { /*TODO*/ }, 形状=圆形, 边框= BorderStroke(1.dp, C...

回答 2 投票 0

如何将按钮添加到首选项屏幕?

我对 Android 开发相当陌生,刚刚遇到了首选项。 我找到了 PreferenceScreen 并想用它创建一个登录功能。我唯一的问题是我不知道我如何

回答 10 投票 0

无法更改按钮的背景颜色和轮廓颜色

<Button android:id="@+id/signInBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="68dp" android:background="@drawable/gradient" android:drawableEnd="@drawable/rounded_arrow_forward_ios_24" android:fontFamily="@font/alata" android:paddingVertical="10dp" android:text="@string/sign_in" android:textFontWeight="600" android:textSize="16sp" app:iconPadding="140dp" app:iconSize="25dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/tagline" /> 我的 XML 布局文件中有两个按钮,一个用于登录,另一个用于注册。登录按钮具有渐变背景,但登录按钮的背景仍保持默认的蓝色。我正在尝试更改注册按钮的轮廓颜色,但尝试使用 background Tint 或 foreground Tint 更改整个背景颜色。我已经尝试过清除缓存并重新启动,但问题仍然存在。 如何正确更改注册按钮的轮廓颜色而不影响整个背景和登录按钮的背景? <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="@color/orange" android:endColor="@color/lightBlue" android:angle="270"/> <corners android:radius="40dp"/> </shape> <Button android:id="@+id/signUpBtn" style="?attr/materialButtonOutlinedStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableEnd="@drawable/rounded_arrow_forward_ios_24" android:fontFamily="@font/alata" android:paddingVertical="10dp" android:text="@string/sign_up" android:textColor="@color/white" android:textFontWeight="600" android:textSize="16sp" app:iconPadding="140dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/signInBtn" /> 要更改注册按钮的轮廓颜色而不影响整个背景,请使用“android:backgroundTint”属性。 将以下行添加到注册按钮 XML android:backgroundTint="@color/DesiredOutlineColor" 将您想要的颜色添加到上面的行。

回答 1 投票 0

在Android 8中使用Shape Drawable设置Button的背景颜色和边框颜色

我尝试在Android 8中使用Shape Drawable(在drawable中创建button_start.xml)设置按钮的背景颜色和边框颜色,但它似乎不起作用。 Button_start.xml 文件: 活动...

回答 2 投票 0

通过 toLeftTo 将文本视图放置在按钮左侧,同时将文本左对齐

下面是一个简单的UI设计,我通过设置android:toLeftTo将Description属性设置为留在按钮的左侧,否则如果描述...

回答 1 投票 0


点击按钮时setOnClickListener不起作用

所以我尝试使用 Kotlin 在 Android Studio 中构建一个小型计算器应用程序。 当用户按下添加按钮时,应该计算两个数字并将其显示在文本视图中,但是当我...

回答 1 投票 0

当我按下clockInOut按钮时,如何获取当前时间并填充到RecyclerView中?

过去两个月我一直在自学如何编码,并决定尝试制作一个计时应用程序。我检查了这段代码中的所有地方,我运行了日志,我什至询问了 chatGPT,并且为此......

回答 1 投票 0

为什么Android无法检测到手机设备上物理按钮的按下?

我正在使用 Android Studio Giraffe 2022.3.1 Patch 2,当我按下物理手机上的电源或音量物理按钮时,日志为空。我使用两种不同的设备,其中一种带有

回答 1 投票 0

使用共享首选项更改按钮的文本 android studio

我正在制作一个带有按钮的简单应用程序。当口袋妖怪被抓住时,我希望文本是“释放”,当没有被抓住时,文本是“抓住!”。当点击按钮时,我想改变

回答 2 投票 0

创建按钮样式并添加背景

我想创建一种更改按钮背景的样式 我写了这个样式,它做了我想要的事情,除了它不会将按钮的背景更改为给定的可绘制对象,它只是保留......

回答 1 投票 0

Android:需要单击后退箭头两次才能返回到上一个 Activity,如何防止它

我有一个活动 A,当我单击活动 A 中的一个按钮并进入另一个活动 B 时,当我单击活动 B 中的后退箭头返回 A 时,它会进入同一个活动...

回答 1 投票 0

Android自定义按钮;改变文字颜色

我制作了一个可以在不同状态下更改背景可绘制的按钮,如下所示: 我制作了一个可以在不同状态下更改背景可绘制的按钮,这样: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/btn_location_pressed" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/btn_location_pressed"/> <!-- focused --> <item android:drawable="@drawable/btn_location"/> <!-- default --> </selector> 这里的问题是,我也尝试像处理可绘制对象一样更改文本颜色,但我无法做到。我已经尝试过 android:textColor 和 android:color 但第一个不起作用,而秒改变了我的背景。 下一个代码是我布局的一部分。关于文本颜色,它仅适用于正常状态文本颜色,因此按下时不会将其更改为白色 <Button android:id="@+id/location_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="5dp" android:background="@drawable/location" android:textSize="15sp" android:textColor="@color/location_color" android:textColorHighlight="#FFFFFF" /> 有人知道吗? 为按钮创建有状态的颜色,就像为背景所做的那样,例如: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Focused and not pressed --> <item android:state_focused="true" android:state_pressed="false" android:color="#ffffff" /> <!-- Focused and pressed --> <item android:state_focused="true" android:state_pressed="true" android:color="#000000" /> <!-- Unfocused and pressed --> <item android:state_focused="false" android:state_pressed="true" android:color="#000000" /> <!-- Default color --> <item android:color="#ffffff" /> </selector> 将 xml 放入 res/drawable 文件夹中的文件中,即 res/drawable/button_text_color.xml。然后只需将可绘制对象设置为文本颜色即可: android:textColor="@drawable/button_text_color" 另一种方法是在你的课堂上: import android.graphics.Color; // add to top of class Button btn = (Button)findViewById(R.id.btn); // set button text colour to be blue btn.setTextColor(Color.parseColor("blue")); // set button text colour to be red btn.setTextColor(Color.parseColor("#FF0000")); // set button text color to be a color from your resources (could be strings.xml) btn.setTextColor(getResources().getColor(R.color.yourColor)); // set button background colour to be green btn.setBackgroundColor(Color.GREEN); 好的,非常简单,首先去 1. res-value并打开colors.xml 2.复制 1 个定义的文本,例如 #FF4081 并更改名称,例如我更改为白色并更改其值,例如我更改为 #FFFFFF 以获得这样的白色值 <color name="White">#FFFFFF</color> 然后在按钮内添加此行 b3.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.White)); 好的 b3 是我的按钮的名称,所以更改按钮的名称,如果您使用白色,则所有其他按钮的名称都将相同,如果您更改不同的颜色,然后将白色更改为您的颜色的名称,但首先您必须在颜色中定义该颜色.xml 就像我在 pont 2 中解释的那样 更改按钮的文字颜色 因为此方法现已弃用 button.setTextColor(getResources().getColor(R.color.your_color)); 我使用以下内容: button.setTextColor(ContextCompat.getColor(mContext, R.color.your_color)); 像这样使用getColorStateList setTextColor(resources.getColorStateList(R.color.button_states_color)) 而不是getColor setTextColor(resources.getColor(R.color.button_states_color)) 如果你想改变按钮的背景颜色,你可以去 res/values/themes/themes.xml 并将“Theme.MaterialComponents.DayNight.DarkActionBar”更改为 Theme.AppCompat.Light.NoActionBar

回答 6 投票 0

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