android-button 相关问题

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

在Android自定义视图设置onClickListener

我试图建立简单的库按钮,库文件夹内我在下面类公共类SimpleImageButton创建扩展AppCompatImageView实现AppCompatImageView.OnClickListener {...

回答 1 投票 0

安卓:如何隐藏按钮点击标题栏

应用程序中使用requestWindowFeature(Window.FEATURE_NO_TITLE)时崩溃;当使用按钮使其全屏其中当试图隐藏标题栏的应用程序崩溃静态INT VARI = 0; ...

回答 1 投票 0

如何设置我的按钮随机颜色与背景颜色。 Android的

对不起,我的英文不好,我的android的初学者,现在我卡住了。现在的问题是我怎么可以设置随机颜色与OnClickListener背景。你也许可以帮我这个...

回答 4 投票 2

按钮单击“事件”以在Android Studio中更新TextView。构建没有错误,但不起作用

已解决:问题在于java没有运行,而不是代码本身。修正了这个按钮的工作原理。当我在模拟器中按下它时,我的按钮(似乎)没有。我正试图......

回答 2 投票 1


如何在Viewpager片段之间同步数据

使用以下代码,我可以单击一个按钮将字符串从一个片段(片段A)发送到MainActivity。我如何从MainActivity中检索字符串并将其显示在片段B上...

回答 2 投票 0

材料按钮背景渐变

有没有一种方法可以为Google材质库中的MaterialButton设置渐变颜色。 app:backgroundTint仅设置颜色,而不设置渐变颜色

回答 4 投票 10

单击2次后,文本大小按钮可用

我有两个Button来增加和减少TextView的文本大小。他们都工作,但是:如果我增加然后减少,首先点击减少按钮将增加文本,并...

回答 2 投票 0

如何通过koltin将ProgressBar(或按钮...)转换为android中的类?

我需要知道如何在“onCreate”方法之外调用ProgressBar(或任何其他类型的按钮)。我在Java中看到我可以调用findViewById(),但它已经在Kotlin中删除了。 ...

回答 3 投票 0

多个东西的一个按钮

我只想实现一个按钮来执行多个操作,例如第一次单击使Textview1可见,第二次单击使Textview2可见,依此类推。这是我的代码它可以工作但是2个动作......

回答 1 投票 -5

如何在按钮上实现超时?

我想在按钮上放一个类似计时器的东西,也就是说,我有一个按钮,按下它后变为不活动,比如说2个小时,两个小时后它再次可点击,但是这样定时器会保持......

回答 2 投票 0

浮动操作栏没有动画显示Snackbar?

在我的Android应用程序中,我使用了Clans的第三方库中的浮动操作按钮。喜欢 -

回答 1 投票 1

android-button背景drawable不起作用

这是我的xml drawable代码,名称为bts theme.xml:

回答 5 投票 2

MaterialButton样式无法在Android 5.0上运行(api 21)

虽然相同的代码库,显示不同的按钮样式是我的问题。在Android 5.1及更高版本上按预期工作。但是对于Android 5.0的MaterialButton样式和背景颜色不起作用。一世'...

回答 1 投票 0

我的LinearLayout Textview和......不会留在不同的手机中

我创建了一个LinearLayout,它有背景图像,它在Android工作室的视觉部分中的Nexus4尺寸确定,但是当我尝试在我的手机中测试时,TextView和EditText和Button被移动了!并不是 ...

回答 1 投票 -1

在片段中正确使用onClick方法来打开新活动是什么?

重新编辑:对于那些感兴趣的人,onClick的方法在下面解决了。事实证明,您无法为控件创建单独的类,因此按钮控件必须位于当前活动类中。 ...

回答 2 投票 0

对于Android Studio中的自定义按钮,我是否必须在MainActivity.java中插入代码?

我在YouTube上找到了一个教程,向我展示了如何制作自定义按钮,但是当我看到3张图片时,有些东西让我感到困惑。它有2个按钮,而最后一个按钮的代码在MainActivity.java中......

回答 1 投票 -1

不改变 colorAccent 就不能改变 MaterialButton 的背景颜色

安卓工作室 3.2.1 这是我的布局: 安卓工作室 3.2.1 这是我的布局: <com.google.android.material.button.MaterialButton android:id="@+id/bittrexJsonViewButton" android:layout_width="0dp" android:layout_height="@dimen/min_height" android:layout_marginStart="@dimen/half_default_margin" android:layout_marginEnd="@dimen/half_default_margin" android:text="@string/json_view" app:layout_constraintBottom_toBottomOf="@+id/binanceJsonViewButton" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/binanceJsonViewButton" app:layout_constraintTop_toTopOf="@+id/binanceJsonViewButton" /> 改变MaterialButton的背景我改变colorAccent在styles.xml <item name="colorAccent">@color/colorAccent</item> 不错。这是工作。 但问题是:我不想改变colorAccent。我想使用不同于 colorAccent 的MaterialButton 的背景颜色 属性: android:background="#aabbcc" 没有帮助。 第一个解决方案 您可以使用app:backgroundTint来改变MaterialButton的背景颜色 <com.google.android.material.button.MaterialButton android:id="@+id/bittrexJsonViewButton" android:layout_width="0dp" android:layout_height="@dimen/min_height" android:layout_marginStart="@dimen/half_default_margin" android:layout_marginEnd="@dimen/half_default_margin" app:backgroundTint="@android:color/holo_orange_dark" android:text="@string/json_view" app:layout_constraintBottom_toBottomOf="@+id/binanceJsonViewButton" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/binanceJsonViewButton" app:layout_constraintTop_toTopOf="@+id/binanceJsonViewButton" /> 第二个解决方案 MaterialButton 在按钮处于活动状态时使用 colorPrimary 作为背景,在禁用时使用 colorOnSurface。所以,你可以在你的主题中定义它并将它应用到材质按钮上 随着MaterialButton你有2个选项: 按照Zaid Mirza的建议使用backgroundTint属性 如果您想覆盖默认样式中的某些主题属性,您可以使用新的materialThemeOverlay 属性。在我看来这是最好的选择。 类似的东西: <style name="Widget.App.ButtonStyle" parent="Widget.MaterialComponents.Button"> <item name="materialThemeOverlay">@style/GreenButtonThemeOverlay</item> </style> <style name="GreenButtonThemeOverlay"> <item name="colorPrimary">@color/green</item> </style> 然后: <com.google.android.material.button.MaterialButton style="Widget.App.ButtonStyle" ../> 至少需要 1.1.0 版本的库。 如果你想设置自定义绘图,你需要制作app:backgroundTint="@null"。只是改变背景颜色app:backgroundTint="@color/yourColor" 我目前正在使用1.3.0-alpha01 <com.google.android.material.button.MaterialButton android:id="@+id/bittrexJsonViewButton" android:layout_width="0dp" android:layout_height="@dimen/min_height" android:layout_marginStart="@dimen/half_default_margin" android:layout_marginEnd="@dimen/half_default_margin" app:backgroundTint="@null" android:background="@drawable/your_custom_drawable" android:text="@string/json_view" app:layout_constraintBottom_toBottomOf="@+id/binanceJsonViewButton" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/binanceJsonViewButton" app:layout_constraintTop_toTopOf="@+id/binanceJsonViewButton" /> 您可以按照以下代码进行操作。 android:background="@color/black" app:backgroundTint="@null" 2020:看来他们刚刚在 2020 年 4 月 1 日修复了这个问题。 它应该在 1.2.0 beta 1 上发布,因为 GitHub 问题已关闭 “固定” backgroundTint也改变了禁用状态的颜色所以对我不好 我能找到的最佳解决方案是通过叠加样式覆盖MaterialButton(仅)的原色 将此代码添加到您的样式中。 将?attr/colorSecondary替换成你想要的任何颜色 <style name="MyButtonTheme" parent="Widget.MaterialComponents.Button"> <item name="materialThemeOverlay">@style/ButtonStyleTextColor</item> </style> <style name="ButtonStyleTextColor"> <item name="colorPrimary">?attr/colorSecondary</item> </style> 为按钮添加主题 <com.google.android.material.button.MaterialButton //.. android:theme="@style/MyButtonTheme"/> 或 如果您使用 MDC 并且想要更改所有按钮的主题: 将此行添加到您的 themes.xml <item name="materialButtonStyle">@style/Button.MyTheme</item> 并将这些行添加到您的 type.xml <style name="Button.MyTheme" parent="Widget.MaterialComponents.Button"> <item name="materialThemeOverlay">@style/ButtonStyleTextColor</item> </style> <style name="ButtonStyleTextColor"> <item name="colorPrimary">?attr/colorSecondary</item> </style> 在那种情况下,您不需要将android:theme="@style/MyButtonTheme"添加到您的MaterialButton 如有错误请告诉我,不要着急降级 对我有用的解决方案如下所述: 在按钮标签上 <Button android:id="@+id/login_btn" style="@style/PrimaryButtonStyle" app:backgroundTint="@null" android:enabled="true" android:text="@string/txtBtnLogin" /> @Style/PrimaryButtonStyle <style name="PrimaryButtonStyle" parent="@style/Widget.MaterialComponents.Button"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_marginTop">5dp</item> <item name="android:textColor">@color/colorPrimary</item> <item name="android:background">@drawable/base_button_style</item> <item name="textAllCaps">false</item> <item name="android:textSize">16sp</item> </style> 此输出 - 按钮背景(浅蓝色)不同于布局背景(相对深蓝色) BackgroundTint 始终适用于材料按钮,但首先,请卸载应用程序并重新安装。有时,在您重新安装应用程序之前,更改可能不会反映出来。 android:backgroundTint 应用于 android:background 和 它们的组合可以通过android:backgroundTintMode来控制 请检查此答案以了解 android:background、android:backgroundTint 和 android:backgroundTintMode 之间的区别 https://stackoverflow.com/a/38080463/14289342 将backgroundTintMode更改为add,然后将显示您的background属性。请参见下面的示例: <com.google.android.material.button.MaterialButton android:id="@+id/bittrexJsonViewButton" android:layout_width="0dp" android:layout_height="@dimen/min_height" android:layout_marginStart="@dimen/half_default_margin" android:layout_marginEnd="@dimen/half_default_margin" android:text="@string/json_view" android:background:"#aabbcc" app:backgroundTintMode="add" app:layout_constraintBottom_toBottomOf="@+id/binanceJsonViewButton" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/binanceJsonViewButton" app:layout_constraintTop_toTopOf="@+id/binanceJsonViewButton" /> 评论询问使用 colorOnSurface 禁用颜色你需要使用主题设置, 像这样: <style name="MaterialRedButton" parent="Widget.MaterialComponents.Button"> <item name="materialThemeOverlay">@style/MaterialRedButtonThemeOverlay</item> </style> <style name="MaterialRedButtonThemeOverlay"> <item name="colorPrimary">@android:color/holo_red_dark</item> <item name="colorOnSurface">@color/white</item> </style> 我有同样的问题,这是它做了什么: 使用材料按钮样式中的一种样式的父级创建一个新样式,并更改其中的背景颜色和背景色调..希望它能与您一起使用.. <style name="DialogMaterialButtonOkay" parent="Widget.Material3.Button.UnelevatedButton"> <item name="background">@color/button_background_color_main</item> <item name="backgroundTint">@color/button_background_color_main</item> </style>

回答 11 投票 0

使用include标记的Android数据绑定

更新说明:上面的示例工作正常,因为1.0-rc4版修复了需要不必要变量的问题。原始问题:我完全按照文档中的描述进行操作......

回答 3 投票 80

Android Studio背景颜色包含在png图像中

我在photoshop cs6中设计了一个按钮并将其保存为png图像。当尝试在android studio中添加它作为imageView或imageButton时,它包含背景颜色。我试过android:backgroud =“@ ...

回答 2 投票 -1

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