我对材料设计的按钮样式感到困惑.我想得到彩色凸起的按钮,如附带的链接,就像在使用部分下看到的"强制停止"和"卸载"按钮一样.是否有可用的样式或我需要定义它们?
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)
所有的风格都消失了,比如触摸动画,阴影,圆角等.
我想知道是否有人可以帮助我.我正在尝试创建自定义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)
以下是主要活动.
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) 我的应用程序中有很多警报对话框.这是默认布局,但我在对话框中添加正负按钮.因此按钮获得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
android android-layout android-edittext material-design android-textinputlayout
我在我的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
今天,我正在尝试安装新的材料组件,这是您需要更改应用程序的父级以从Theme.MaterialComponents继承。我之所以这样做,是因为我想使用底部导航更好的波纹。但是之后,几乎所有应用程序中的按钮都变得更加膨松。
我该怎么做才能恢复到之前的状态(右图)?
我已将 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) 我想使用带有默认警报对话框的新材料轮廓按钮。
我在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
有什么方法可以更改默认对话框按钮的颜色,或者我需要为此做自定义对话框吗?
这是我的对话:
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
阅读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