相关疑难解决方法(0)

Android Material Design按钮样式

我对材料设计的按钮样式感到困惑.我想得到彩色凸起的按钮,如附带的链接,就像在使用部分下看到的"强制停止"和"卸载"按钮一样.是否有可用的样式或我需要定义它们?

http://www.google.com/design/spec/components/buttons.html#buttons-usage

我找不到默认的按钮样式.

例:

 <Button style="@style/PrimaryButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Calculate"
    android:id="@+id/button3"
    android:layout_below="@+id/editText5"
    android:layout_alignEnd="@+id/editText5"
    android:enabled="true" />
Run Code Online (Sandbox Code Playgroud)

如果我尝试通过添加更改按钮的背景颜色

    android:background="@color/primary"
Run Code Online (Sandbox Code Playgroud)

所有的风格都消失了,比如触摸动画,阴影,圆角等.

android button material-design android-5.0-lollipop

293
推荐指数
9
解决办法
45万
查看次数

如何更改AlertDialog的主题

我想知道是否有人可以帮助我.我正在尝试创建自定义AlertDialog.为此,我在styles.xml中添加了以下代码行

<resources>
 <style name="CustomAlertDialog" parent="android:Theme.Dialog.Alert">
  <item name="android:windowBackground">@drawable/color_panel_background</item>
 </style>
</resources>
Run Code Online (Sandbox Code Playgroud)
  • color_panel_background.9.png位于drawable文件夹中.这也可以在Android SDK res文件夹中找到.

以下是主要活动.

package com.customdialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class CustomDialog extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.setTheme(R.style.CustomAlertDialog);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("HELLO!");
        builder .setCancelable(false)
          .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               //MyActivity.this.finish();
           }
       })
       .setNegativeButton("No", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int …
Run Code Online (Sandbox Code Playgroud)

alert android themes dialog

230
推荐指数
9
解决办法
33万
查看次数

如何在android 5中更改默认对话框按钮文本颜色

我的应用程序中有很多警报对话框.这是默认布局,但我在对话框中添加正负按钮.因此按钮获得Android 5(绿色)的默认文本颜色.我试图改变它但没有成功.知道如何改变文字颜色吗?

My Custom对话框:

public class MyCustomDialog extends AlertDialog.Builder {

    public MyCustomDialog(Context context,String title,String message) {
        super(context);

        LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
        View viewDialog = inflater.inflate(R.layout.dialog_simple, null, false);

        TextView titleTextView = (TextView)viewDialog.findViewById(R.id.title);
        titleTextView.setText(title);
        TextView messageTextView = (TextView)viewDialog.findViewById(R.id.message);
        messageTextView.setText(message);

        this.setCancelable(false);

        this.setView(viewDialog);

    } }
Run Code Online (Sandbox Code Playgroud)

创建对话框:

MyCustomDialog builder = new MyCustomDialog(getActivity(), "Try Again", errorMessage);
builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            ...
                        }
}).show();
Run Code Online (Sandbox Code Playgroud)

negativeButton是一个默认的对话框按钮,采用Android 5 Lollipop的默认绿色.

非常感谢

带绿色按钮的自定义对话框

android textcolor android-layout android-alertdialog android-5.0-lollipop

127
推荐指数
12
解决办法
12万
查看次数

26
推荐指数
4
解决办法
3万
查看次数

在AppCompat中使用基于材质的对话框主题

我在我的Manifest中有一个活动,我习惯用Dialog主题设置风格.我找不到如何在AppCompat库中替换它.

  <activity
            android:name=".LoginActivity"
            android:theme="@android:styles/Theme.Holo.Dialog" 
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:label="Login" >
Run Code Online (Sandbox Code Playgroud)

有基于材料的等价物吗?

android themes android-appcompat material-design material-theme

21
推荐指数
3
解决办法
4万
查看次数

更改“应用程序”的主题后,“材料组件”主题对话框按钮变得浮肿

今天,我正在尝试安装新的材料组件,这是您需要更改应用程序的父级以从Theme.MaterialComponents继承。我之所以这样做,是因为我想使用底部导航更好的波纹。但是之后,几乎所有应用程序中的按钮都变得更加膨松。

我该怎么做才能恢复到之前的状态(右图)?

左侧是材料版本,右侧是appcompat版本 左侧是材料版本,右侧是appcompat版本

android material-design material-components-android

7
推荐指数
1
解决办法
1144
查看次数

将 MaterialAlertDialogBu​​ilder 与材质主题一起使用

我已将 android 应用程序设置为使用材料主题

<style name="AppTheme" parent="AppTheme.Base"></style>

<style name="AppTheme.Base" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="android:textColorSecondary">@android:color/white</item>
        <item name="android:textColorHint">@android:color/darker_gray</item>
        <item name="searchViewStyle">@style/SearchViewStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

在我的活动/片段中,我试图调用材料警报对话框

new MaterialAlertDialogBuilder(mAppContext)
                            .setTitle("Title")
                            .setMessage("Message")
                            .setPositiveButton("Ok", null)
                            .show();
Run Code Online (Sandbox Code Playgroud)

在运行时,这会引发以下 IllegalArgumentException 异常

java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
        at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:240)
        at com.google.android.material.internal.ThemeEnforcement.checkAppCompatTheme(ThemeEnforcement.java:211)
        at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:146)
        at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:78)
        at com.google.android.material.dialog.MaterialDialogs.getDialogBackgroundInsets(MaterialDialogs.java:55)
        at com.google.android.material.dialog.MaterialAlertDialogBuilder.<init>(MaterialAlertDialogBuilder.java:116)
        at com.google.android.material.dialog.MaterialAlertDialogBuilder.<init>(MaterialAlertDialogBuilder.java:102)
        at com.syl.app.fragments.AlarmNotificationDetailFragment$2.onClick(UserFragment.java:265)
        at android.view.View.performClick(View.java:5207)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:941)
        at android.view.View$PerformClick.run(View.java:21177)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at …
Run Code Online (Sandbox Code Playgroud)

android

7
推荐指数
1
解决办法
5387
查看次数

使用带有警报对话框的最新材料概述按钮

我想使用带有默认警报对话框的新材料轮廓按钮。

我在style.xml中创建了样式,如下所示

<style name="OutlinedButton" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="strokeColor">@color/colorAccent</item>
    <item name="strokeWidth">2dp</item>
</style>

<style name="MaterialDialogStyle" parent="Theme.MaterialComponents.Dialog.Alert">
    <item name="android:textColorPrimary">@color/colorAccent</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorPrimary">@color/colorAccent</item>
    <item name="buttonStyle">@style/OutlinedButton</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我正在使用新的 Material Components 主题来设置“是”和“否”按钮的样式。

现在,我通过将其设置为 AlertDialog 构建器来在代码中使用上述样式。

AlertDialog.Builder builder = new AlertDialog.Builder(ProductListActivity.this, R.style.MaterialDialogStyle);
Run Code Online (Sandbox Code Playgroud)

但输出如下 在此输入图像描述

有没有办法将最新材料概述按钮与默认警报对话框一起使用?如果有什么区别的话,我正在使用设计支持库中的材料组件。

android android-alertdialog android-styles material-design material-components-android

5
推荐指数
1
解决办法
2512
查看次数

更改对话框按钮颜色

有什么方法可以更改默认对话框按钮的颜色,或者我需要为此做自定义对话框吗?

这是我的对话:

private void removeItem(final int position) {
    /** Create dialog which ask if user is sure about delete name from list **/
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Delete player");
    builder.setIcon(R.mipmap.ic_launcher);
    builder.setMessage("Do you want to delete player: \"" + mNameList.get(position).getText1() + "\"?")
            .setCancelable(false)

            /** If user click "ok" button, delete player from list and save changes **/
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    mNameList.remove(position);
                    mAdapter.notifyItemRemoved(position);
                    saveData();
                }
            })

            /** If user click "cancel" button, …
Run Code Online (Sandbox Code Playgroud)

android android-alertdialog material-design material-components material-components-android

4
推荐指数
2
解决办法
3711
查看次数

MaterialComponents AlertDialog 文本颜色

阅读MaterialComponents 主题警报对话框按钮https://medium.com/@lcdsmao/material-design-custom-alert-dialog-5a9cab3ade11我设置AlertDialog了新材料主题的按钮和文本颜色。

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <!-- AlertDialog -->
    <item name="materialAlertDialogBodyTextStyle">@style/MaterialAlertDialogTextTheme</item>
    <item name="materialAlertDialogTheme">@style/MaterialAlertDialogButtonsTheme</item>
</style>

<!-- AlertDialog text -->
<style name="MaterialAlertDialogTextTheme" parent="MaterialAlertDialog.MaterialComponents.Body.Text">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:colorAccent">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorPrimaryitem>
    <item name="android:textSize">14sp</item>
    <item name="android:textStyle">bold</item>
</style>

<!-- AlertDialog buttons -->
<style name="MaterialAlertDialogButtonsTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
    <item name="buttonBarPositiveButtonStyle">@style/AlertDialog.Button</item>
    ...
Run Code Online (Sandbox Code Playgroud)

创建AlertDialogFragment使用后

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    super.onCreateDialog(savedInstanceState)

    return MaterialAlertDialogBuilder(context!!).apply {
        ...
    }.create()
} …
Run Code Online (Sandbox Code Playgroud)

android android-alertdialog material-design material-components material-components-android

3
推荐指数
1
解决办法
881
查看次数