Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改对话框按钮以清除styles.xml中的涟漪效果_Android_Android Layout_Android Alertdialog_Android Styles - Fatal编程技术网

Android 更改对话框按钮以清除styles.xml中的涟漪效果

Android 更改对话框按钮以清除styles.xml中的涟漪效果,android,android-layout,android-alertdialog,android-styles,Android,Android Layout,Android Alertdialog,Android Styles,我有一个简单的对话框,有两个按钮,正按钮和负按钮,它采用我在styles.xml中定义的简单样式布局。我想取消按钮有一个清晰的背景,但仍然有用户反馈时,触摸它(如红色的涟漪效应)。我已经试了两天了,但是运气不好。任何意见都会很好 使用连锁反应: 我为下一个布局编写的代码使布局具有清晰的取消背景,但没有连锁反应。但我确实得到了“是”的连锁反应: <style name="AlertDialogThemeTesting" parent="Theme.AppCompat.Dialog.Ale

我有一个简单的对话框,有两个按钮,正按钮和负按钮,它采用我在styles.xml中定义的简单样式布局。我想取消按钮有一个清晰的背景,但仍然有用户反馈时,触摸它(如红色的涟漪效应)。我已经试了两天了,但是运气不好。任何意见都会很好

使用连锁反应:

我为下一个布局编写的代码使布局具有清晰的取消背景,但没有连锁反应。但我确实得到了“是”的连锁反应:

 <style name="AlertDialogThemeTesting" parent="Theme.AppCompat.Dialog.Alert">
    <item name="colorControlHighlight">@color/Red</item>
    <item name="colorControlActivated">@color/Red</item>
    <item name="colorControlNormal">@color/Red</item>
    <item name="android:textColor">@color/Black</item>
    <item name="android:textColorPrimary">@color/Gray</item>
    <item name="android:buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
    <item name="android:buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
</style>

<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
    <item name="android:textColor">@color/Black</item>
    <item name="android:background">?attr/selectableItemBackgroundBorderless</item>
    <item name="backgroundTint">@color/Clear</item>
</style>

<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
    <item name="android:textColor">@color/Black</item>
    <item name="android:background">?attr/selectableItemBackgroundBorderless</item>
    <item name="android:backgroundTint">@color/Gold</item>
</style>

定义您的按钮,如下所示

<LinearLayout

    android:id="@+id/test_btn"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_marginTop="68dp"
    android:background="@drawable/button_effect"
    app:layout_constraintTop_toTopOf="parent"
    tools:layout_editor_absoluteX="0dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:fontFamily="@font/titilliumweb_bold"
        android:gravity="center"
        android:text="Test Button"
        android:textColor="@color/UcabWhite" />

</LinearLayout>
我已经测试过了,效果很好。试试看,如果你有任何困难,请告诉我

编辑

定义警报对话框,如下所示。当长按“取消”按钮时,可以看到涟漪效应。但是,当您只需单击它,就没有时间显示effcet as警报了

 final AlertDialog.Builder alert = new AlertDialog.Builder(this, R.style.AppTheme);
    alert.setTitle("Delete Profile?")
            .setMessage("Are you sure you want to delete")
            .setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                            int whichButton) {
                            finish();
                            dialog.dismiss();
                        }
                    })
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });

    final AlertDialog dialog = alert.create();
    dialog.show();

    Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
    negativeButton.setBackgroundResource(R.drawable.button_mini_oval);

这会有帮助。

您是否为“取消”按钮检查了不同颜色的效果是否正常?是的,如果我将其更改为除透明或白色之外的任何颜色,它似乎都能正常工作。这就是为什么这是如此奇怪@sajithp请看我下面的答案。你尝试过属性colorButtonNormal@cutiko吗?是的,它不会改变任何东西。是的,我知道这会工作,因为它使用自定义布局,但我真的想让对话框的正/负按钮在没有自定义布局的情况下工作。因为我必须重写一个合适的块,因为我有大约8个对话框,所有不同的设置。您知道如何将AlertDialog.BUTTON设置为其他类似的布局吗?在原始帖子之后添加了代码。我使用的XML已经在顶部链接,这就是样式代码。谢谢你的帮助!该代码与具有连锁反应的setBackgroundResource一起工作,例如
negativeButton。setBackgroundResource(R.drawable.rippleEffect)
不需要点击它,因为它仍然注册。谢谢你的帮助!我很乐意帮忙。
   <ripple xmlns:android="http://schemas.android.com/apk/res/android"
     android:color="@color/colorPrimary"     //colour you want the effect
     android:exitFadeDuration="@android:integer/config_shortAnimTime">
       <selector>
          <item>
             <color android:color="@android:color/transparent" />
          </item>
      </selector>
   </ripple>
test.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
 final AlertDialog.Builder alert = new AlertDialog.Builder(this, R.style.AppTheme);
    alert.setTitle("Delete Profile?")
            .setMessage("Are you sure you want to delete")
            .setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                            int whichButton) {
                            finish();
                            dialog.dismiss();
                        }
                    })
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });

    final AlertDialog dialog = alert.create();
    dialog.show();

    Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
    negativeButton.setBackgroundResource(R.drawable.button_mini_oval);