最近我从支持库切换到com.google.android.material:material:1.0.0
但是现在我有一个问题,在这个页面上有一个注释https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md
注意:使用"材质成分"主题可启用自定义视图填充程序,该填充程序将使用"材质"对应项替换默认组件.目前,这仅使用MaterialButton替换Button XML组件.
我正在使用的主题
Theme.MaterialComponents.Light.NoActionBar
Run Code Online (Sandbox Code Playgroud)
它完全按照它在说明中所说的,它将AlertDialog按钮替换为MaterialButtons,但问题是默认情况下MaterialButtons是彩色背景,现在按钮看起来像这样:
我怎样才能让它们再次无边界和无背景?
PS我正在使用警报构建器来创建警报对话框:
android.app.AlertDialog.Builder
Run Code Online (Sandbox Code Playgroud) android android-alertdialog android-styles material-design material-components-android
是否可以在Android应用程序中只显示图像弹出/启动?它类似于覆盖AlertDialog的普通视图,因此它只包含一个图像而不包含任何其他内容.
解决方案: 感谢@ blessenm的帮助,我找到了答案.将活动屏蔽为对话似乎是理想的方式.以下是我使用的代码.可以根据需要调用此对话框样式活动,与启动新活动的方式相同
ImageDialog.java
public class ImageDialog extends Activity {
private ImageView mDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_dialog_layout);
mDialog = (ImageView)findViewById(R.id.your_image);
mDialog.setClickable(true);
//finish the activity (dismiss the image dialog) if the user clicks
//anywhere on the image
mDialog.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
your_dialog_layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image_dialog_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity = "center">
<ImageView
android:id="@+id/your_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src = "@drawable/your_image_drawable"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
为活动设置以下样式以实现此目的至关重要:
styles.xml
<style name="myDialogTheme" …
Run Code Online (Sandbox Code Playgroud) 我正在尝试DialogFragment
使用自定义视图创建AlertDialog
.必须从xml中扩充此视图.在我的DialogFragment
班上,我有:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle("Title")
.setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, null))
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, null)
.create();
}
Run Code Online (Sandbox Code Playgroud)
我尝试过其他通胀方法,.setView()
例如:
.setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, (ViewGroup) getView(), false))
Run Code Online (Sandbox Code Playgroud)
和
.setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, (ViewGroup) getTargetFragment().getView(), false))
Run Code Online (Sandbox Code Playgroud)
在显示此对话框的片段中设置目标片段之后.
所有这些尝试使我的自定义视图膨胀都会导致以下异常:
E/AndroidRuntime(32352): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
E/AndroidRuntime(32352): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:214)
E/AndroidRuntime(32352): at com.android.internal.app.AlertController.installContent(AlertController.java:248)
E/AndroidRuntime(32352): at android.app.AlertDialog.onCreate(AlertDialog.java:314)
E/AndroidRuntime(32352): at android.app.Dialog.dispatchOnCreate(Dialog.java:335)
E/AndroidRuntime(32352): at android.app.Dialog.show(Dialog.java:248)
E/AndroidRuntime(32352): at android.support.v4.app.DialogFragment.onStart(DialogFragment.java:339)
E/AndroidRuntime(32352): at android.support.v4.app.Fragment.performStart(Fragment.java:1288)
E/AndroidRuntime(32352): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:873)
E/AndroidRuntime(32352): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1041)
E/AndroidRuntime(32352): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:625)
E/AndroidRuntime(32352): at …
Run Code Online (Sandbox Code Playgroud) android android-inflate android-fragments layout-inflater android-alertdialog
如何使用时,将文本设置为粗体的一部分AlertDialog
的setMessage()
?添加<b>
和</b>
我String
不起作用.
我在Eclipse中创建了一个新的应用程序,目标是Jelly Bean.这是所有自动创建的代码.清单将应用程序主题设置为AppName:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
. . .
Run Code Online (Sandbox Code Playgroud)
对于值dir中的样式,它转换为AppBaseTheme:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. …
Run Code Online (Sandbox Code Playgroud) 我打算用layout_weight = 1创建3个按钮,对自定义对话框不感兴趣.所以我写了下面的代码.它不工作.总是是按钮给我null.这段代码怎么了?
AlertDialog dialog= new AlertDialog.Builder(this).create();
dialog.setIcon(R.drawable.alert_icon);
dialog.setTitle("title");
dialog.setMessage("Message");
dialog.setButton(AlertDialog.BUTTON_POSITIVE,"Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
Button yesButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
Log.w("Button",""+yesButton);//here getting null
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f);
yesButton.setLayoutParams(layoutParams);
dialog.show();
Run Code Online (Sandbox Code Playgroud)
此致,Android开发人员.
我创建了包含4个按钮的AlertDialog
OptionDialog = new AlertDialog.Builder(this);
OptionDialog.setTitle("Options");
LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = li.inflate(R.layout.options, null, false);
background = (Button) v.findViewById(R.id.bkgSpinnerLabel);
SoundVib = (Button) v.findViewById(R.id.SoundVibSpinnerLabel);
OptionDialog.setView(v);
OptionDialog.setCancelable(true);
OptionDialog.setNeutralButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
background.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SetBackground();
// here I want to dismiss it after SetBackground() method
}
});
SoundVib.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent soundVibIntent = new Intent(SebhaActivity.this, EditPreferences.class);
startActivity(soundVibIntent);
}
});
OptionDialog.show();
Run Code Online (Sandbox Code Playgroud)
我想在SetBackground()方法之后解雇它,我该怎么做呢?提前致谢.
点击PositiveButton后我可以不解雇我的AlertDialog吗?
我想继续在对话框中显示我的ArrayAdapter listWords上的更新内容.
这是我的代码.
AlertDialog.Builder sayWindows = new AlertDialog.Builder(MapActivity.this);
final EditText saySomething = new EditText(MapActivity.this);
sayWindows.setPositiveButton("ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
say = userName + " Says: "+saySomething.getText();
showPosition.setText(say);
}
});
sayWindows.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
sayWindows.setAdapter(listWords, null);
sayWindows.setView(saySomething);
sayWindows.create().show();
Run Code Online (Sandbox Code Playgroud) 我需要AlertDialog
使用自定义视图.a的消息AlertDialog
有一个默认的填充但是当我设置一个视图它没有填充时,我想要获得与默认消息相同的填充.我正在使用扩展Holo主题的风格(如果这是相关的).
AlertDialog.Builder builder = new AlertDialog.Builder(PlaylistListView.this.getContext());
builder.setTitle("Title");
builder.setView(inflate(context, R.layout.music_player_create_dialog, null));
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();
Run Code Online (Sandbox Code Playgroud)
这是内容的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/abc_dialog_padding_material"
android:paddingRight="@dimen/abc_dialog_padding_material"
android:paddingTop="@dimen/abc_dialog_padding_top_material"
android:paddingBottom="@dimen/abc_dialog_padding_top_material">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title:"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:background="@null"
android:layout_marginTop="20dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/divider"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我编写了一个显示弹出对话框的android代码,但是我想将背景颜色从黑色更改为白色,然后是写入的颜色.
这是对话框的代码:
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Boolean welcomeScreenShown = mPrefs.getBoolean(welcomeScreenShownPref, false);
if (!welcomeScreenShown) {
String whatsNewText = getResources().getString(R.string.Text);
new AlertDialog.Builder(this).setMessage(whatsNewText).setPositiveButton(
R.string.ok, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(welcomeScreenShownPref, true);
editor.commit(); // Very important to save the preference
}
Run Code Online (Sandbox Code Playgroud)