我正在使用以下材料设计库
implementation "com.google.android.material:material:1.2.0-alpha01"
这就是我实现材质切换按钮的方式
<com.google.android.material.button.MaterialButtonToggleGroup
id="@+id/toggleBtnGroup"
app:singleSelection="true"
android:id="@+id/toggle_button_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:checkedButton="@+id/leftAlign">
<com.google.android.material.button.MaterialButton
id="@+id/leftAlign"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left"/>
<com.google.android.material.button.MaterialButton
id="@+id/centerAlign"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Center"/>
<com.google.android.material.button.MaterialButton
id="@+id/rightAlign"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right"/>
</com.google.android.material.button.MaterialButtonToggleGroup>
Run Code Online (Sandbox Code Playgroud)
现在,当我选择其他按钮时,一次仅选择 1 个按钮,如何确保如果用户再次选择所选按钮,它不会被取消选择。因此本质上,我希望在特定时间至少选择这些按钮之一。
一个人会怎样做呢?
android android-button kotlin material-components material-components-android
我希望我的按钮有圆角,例如:
要在 Android 中使用材质主题实现此目的,请将:设置shapeAppearanceSmallComponent为有一个rounded角。
但设置shapeAppearanceSmallComponent也会影响所有其他组件,例如EditText现在它们也被舍入。
因此,我没有将其设置为shapeAppearanceSmallComponent,而是创建了一个shapeMaterialOverlay. 将此覆盖设置为 abuttonStyle并将主题中的此按钮样式设置为默认按钮样式。
它有效,但仅适用于默认按钮。如果我需要TextButton这样的:
<Button
...
style="@style/Widget.MaterialComponents.Button.TextButton"/>
Run Code Online (Sandbox Code Playgroud)
不会TextButton被舍入。因此,作为一种解决方法,我创建了MyTextButton从那里延伸TextButton并设置shapeOverlay在那里的样式。
所以现在如果我需要一个TextButton,我会这样做:
<Button
...
style="@style/Widget.MaterialComponents.Button.MyTextButton"/>
Run Code Online (Sandbox Code Playgroud)
反而。
我必须对所有其他按钮类型执行此操作。我想知道这种方法是否正确,如果不正确,有人可以指导我如何正确执行此操作吗?
非常感谢。
android android-button material-design material-components material-components-android
这是我的 Buttons.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="50dp"/>
<gradient android:startColor="#8E8816"
android:endColor="#145038"
android:angle="270" />
<stroke android:color="#680D0D" android:width="5dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
这是我的 Activity_main.xml 我尝试将 android:background 更改为 android:src 但它也不起作用
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@color/teal_700"
tools:context=".MainActivity">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/buttons"
android:text="Button" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
只有角属性工作正常
不仅是中风,而且背景也没有改变,我没有明白我做错的地方......任何人都可以帮助我
这里将背景应用为 android:background="@drawable/buttons" Button_image后按钮的外观如何
android button android-button android-styles material-components-android
我试图在Android 8中使用Shape Drawable(在drawable中创建button_start.xml)设置按钮的背景颜色和边框颜色,但它似乎不起作用。
我在正常状态下有一个3d查看按钮,右侧和底部都有3dp填充,当我按下按钮时,我想让它看起来像这里左边和顶部的3dp填充.但是当我更改项目形状的按下状态的填充值时,即使按钮处于正常状态/未按下,填充中的更改也会显示.
我的按钮看起来像这样:

按下时我也希望它看起来像这样:

btn_gray1.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#acacac" />
<stroke
android:width="0dp"
android:color="#acacac" />
<corners
android:radius="0dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="#c2c2c2"/>
<stroke
android:width="0dp"
android:color="#c2c2c2" />
<corners
android:radius="0dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
btn_gray2.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#acacac" />
<stroke
android:width="0dp"
android:color="#acacac" />
<corners
android:radius="0dp" />
<padding
android:left="0dp"
android:top="0dp"
android:right="3dp"
android:bottom="3dp" />
</shape>
</item>
<item> …Run Code Online (Sandbox Code Playgroud) 我使用以下方法声明一个按钮:
Button btn = new Button(this);
btn.setText(itemSet[i]);
btn.setId(i);
Run Code Online (Sandbox Code Playgroud)
我需要添加一个自定义属性,该属性将在单击时使用。
有没有办法做到这一点?
如何获得这个带渐变背景的按钮视图?
我google了很多但没找到什么
我认为一个在另一个上的重叠是因为相对布局..

在按照以下条件单击"boton_continuar"按钮时,我正在尝试显示吐司:EditExt vacuum(numero_celular)和ckeckbox(check)选中no.这是我的代码
boton_continuar.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//Verificamos que se halla clikeado y se halla ingresado
if(check.isChecked() && numero_celular.getText().length() != 0){
Intent intent = new Intent(RegisterActivity.this, PrincipalActivity.class);
startActivity(intent);
}else{
Context contexto = getApplicationContext();
if(!check.isChecked()){
Toast.makeText(contexto, "Debe aceptar los términos", 2000);
}
if(numero_celular.getText().length() == 0){
Toast.makeText(contexto, "Debe ingresar su número", 2000);
}
}
}});
Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试通过xml 更改切换按钮的文本颜色.
我已经引用了链接,但它只更改了切换按钮的背景颜色,而不是其文本.
我试过这种方法:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#ffffff" />
<item android:state_checked="false" android:color="#000000" />
</selector>
Run Code Online (Sandbox Code Playgroud)
但只有背景在变化.
注意:我不想在代码中执行此操作,因为有21个切换按钮,并且每个按钮的设置监听器都不好.
android toggle togglebutton android-button android-togglebutton

我试图让馅饼的每个切片成为一个按钮.馅饼是图像视图中的一堆矢量drawables.我不一定需要点击实际的饼图片.我正在考虑使用Path绘制透明形状并将其放在顶部并将其设为按钮,但据我所知,drawables无法点击.
我读了一篇博文,其中显然使用路径来制作自定义形状的图像视图,我知道图像视图是可点击的,但似乎在博客文章中的实现图像视图仍然是矩形的,但博客使用的位图在示例中,只是在图像视图内修剪为自定义形状.这是我所指的帖子:http://www.androidhub4you.com/2014/10/android-custom-shape-imageview-rounded.html
请像五岁那样向我解释一下.我对编程比较陌生.如果不是Android Studio的自动一切,我不会在这里.
谢谢.
android view android-imageview android-button onclicklistener
android ×10
android-button ×10
material-components-android ×3
button ×2
colors ×1
kotlin ×1
shape ×1
toggle ×1
togglebutton ×1
view ×1
xml ×1