- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在设置一个新的应用程序,并发现 Material 按钮的高度与我设置的尺寸不匹配。所以我尝试了常规按钮,正如你们在下面的屏幕截图中看到的那样。这些按钮具有不同的高度,尽管它们的高度与您在我的代码中看到的相同。
如何使用 MaterialButton 获得正常高度?
谢谢。
公共(public)类 MainActivity 扩展 AppCompatActivity {
MaterialButton materialButton;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setId(getGeneratedId());
setContentView(linearLayout);
int buttonWidth = getResources().getDimensionPixelSize(R.dimen.buttonWidth);
int buttonHeight = getResources().getDimensionPixelSize(R.dimen.buttonHeight);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(buttonWidth, buttonHeight);
materialButton = new MaterialButton(this);
materialButton.setId(getGeneratedId());
materialButton.setLayoutParams(layoutParams);
materialButton.setBackgroundColor(Color.BLUE);
materialButton.setText("MatrialB");
materialButton.setTextColor(Color.WHITE);
button = new Button(this);
button.setId(getGeneratedId());
button.setLayoutParams(layoutParams);
button.setBackgroundColor(Color.RED);
button.setText("Button");
button.setTextColor(Color.WHITE);
linearLayout.addView(materialButton);
linearLayout.addView(button);
}
Integer getGeneratedId() {
return ViewCompat.generateViewId();
}
}
最佳答案
我相信 MaterialButton 顶部和底部的空间来自 android:insetTop
/android:insetBottom
对我来说是 6dp
使用 Material 组件 1.0.0。我不确定如何以编程方式设置这些,但可以在 xml 中轻松完成:
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:insetBottom="0dp"
android:insetTop="0dp"/>
关于java - MaterialButton 与 Button 的尺寸差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56840355/
我在布局中有四个 MaterialButton,我想在按下其中一个按钮时更改所有按钮的颜色。其中两个带有一种颜色,另外两个带有另一种颜色。我该怎么做? 最佳答案 只需调用 setState() 并使用
安卓工作室 3.3.2 classpath 'com.android.tools.build:gradle:3.3.2' 在我的新 Android 项目中,我想使用新的 android Materia
我正在尝试使用 MaterialButton,但它无法正常工作。我的 androidx 依赖 implementation 'androidx.appcompat:appcompat:1.0.2' i
我正在尝试创建一个从 MaterialButton 扩展的自定义 View 并在代码中应用样式,因此我不需要在 xml 中执行此操作。 class CustomRedButton @JvmOverlo
我想以编程方式创建一个按钮,如此处的设计指南中所定义:https://material.io/design/components/buttons.html#outlined-button ,看起来像这
我正在这样做 但是图标显示在文本的左侧,图标重力对图标位置没有影响。 在普通按钮中,我们曾经使用 drawableRight 实现相同的效果,但这里没有找到方法。 最佳答案 app:icon="@d
我想将图标放在 materialButton 的顶部,如下所示: 但是我在 MaterialButton 中找不到任何属性来设置应用程序的重力:图标到顶部。我只能将它设置为开始或结束。有没有什么方法可
我正在尝试使用一个 Material 按钮,我想要在最左边有一个图标,然后在中间有一些文本。但是,例如,当我将图标放在左侧时,我可以清楚地看到文本被推到右侧。有什么办法可以避免这种情况吗?我希望文本居
我正在使用最新版本的 com.google.android.material:material 库(即 1.1.0-alpha03),并且我有一个 MaterialButton 使用图标定义,无文本,
这是按钮的代码 这是尝试在按钮中添加描边时的图像 Image With added stroke in button 下面是没有笔画宽度的代码 Image without Stroke 我尝试了不
您好,我遇到了在 Android 上对齐 Material 按钮中的图标的问题。我有 match_parent 宽度、文本和文本旁边的图标的按钮。我想将图标 8dp 左对齐到文本,我尝试通过 com.
安卓6.0 安卓工作室 3.6 在我的 fragment 中,当单击按钮时,我会像这样“即时”更改样式: bluetoothPageViewModel.isDisableModeLiveData(
参见: 代码: 样式.xml rounded 20dp 为了确认 Material 按钮包含完整空间,我将
我正在尝试构建一个带有边框按钮的布局,如下所示(预期行为)。从 Material design 文档中,我了解到 Outlined Material Button 似乎非常适合我的目的。我在我的布局中
我们正在使用 Material Components 1.0.0,并希望在整个应用程序中更改 MaterialButton 的样式。我们创建了自己的样式,扩展了组件库中的样式。现在我们有类似的东西:
我正在使用 supportLibrary = "28.0.0-beta01" 版本。 这是我在 .xml 文件中的代码: 到位于按钮左侧的可绘制对象的代码图标。我想将按钮设置为中心。我想达到这个结果
我正在使用支持库中的 Materialbutton。我希望图标位于文本的右侧?我似乎找不到如何去做。感谢任何帮助 最佳答案 您可以使用 app:iconGravity 属性。 使用 app:iconG
我这辈子都想不通按钮宽度的问题。我不知道按钮当前的宽度是多少,但我可以告诉你,当我告诉它时它并没有减少。它保持完全相同,并且在增加 minWidth 值时甚至不会增加。 Material( chi
我尝试向 MaterialButton 添加一个简单的 BadgeDrawable,但没有显示徽章。 我已经在我的 build.gradle 中尝试了以下版本: 'com.google.android
如果我设置 Theme.MaterialComponents.Light 作为我的主题,如果我在 xml 布局中使用这两个按钮,它们之间会有什么区别吗? 正如我所看到的,它们都表现为 Materi
我是一名优秀的程序员,十分优秀!