这是我显示的地方AlertDialog:
public void showCenteredInfoDialog(TextView _title, TextView _message) {
_title.setGravity(Gravity.CENTER);
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton("OK", null);
builder.setCustomTitle(_title);
builder.setMessage(_message.getText());
AlertDialog dialog= builder.show();
TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
messageView.setGravity(Gravity.CENTER);
}
Run Code Online (Sandbox Code Playgroud)
我想要的字体是monospace.
我需要修改xml文件吗?Java 可以单独处理吗?(如果 Java 可以处理它,它可能需要 API 21,是吗?)
我想知道添加messageView.setFontFeatureSettings("...");或messageView.setTypeface(...)以某种方式引用monospace是否可行。我找不到 的 String 参数的语法setFontFeatureSettings。
我从这里复制了整个代码
并在AlertDialog. 现在,当我调试应用程序时,onClick()不会调用该应用程序。
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(R.layout.keypad_layout);
builder.setCancelable(false).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.setPositiveButton("Modify", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.create().show();\
Run Code Online (Sandbox Code Playgroud)
警报对话框正在显示,正负按钮可以工作,唯一的问题是我无法访问布局内的视图
我正在使用 AlertDialog 要求用户在长按视图时输入数值。这使用 Android 软键盘。为了获得更好的用户体验,我希望键盘“Enter”按钮以编程方式单击警报对话框的肯定按钮并运行它的 onClick。这真的很尴尬,因为我在对话框对象中找不到任何对肯定按钮的引用。代码来说明:
customStakeView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Custom Stake");
customStakeSet = false;
// Set up the input
final EditText input = new EditText(context);
input.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
// Specify the type of input expected;
input.setInputType(InputType.TYPE_CLASS_NUMBER);
input.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if(keyEvent.getAction() == KeyEvent.ACTION_DOWN){
if(!input.getText().toString().equals("")){
switch (keyCode){
case KeyEvent.KEYCODE_ENTER:
//Positive Button Outcome
}
}
}
return false;
}
});
builder.setView(input);
// Set …Run Code Online (Sandbox Code Playgroud) 我希望制作一个自定义AlertDialog全屏,就像新的活动屏幕一样。
尝试了这些答案,但仍然不起作用
public void newDialog(final Context c){
final AlertDialog alertDialog;
LayoutInflater layoutInflater = LayoutInflater.from(c);
dialogueView = layoutInflater.inflate(R.layout.layout_dialogue, null);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(c);
alertDialogBuilder.setView(dialogueView);
alertDialog = alertDialogBuilder.create();
dialogueView.findViewById((R.id.closeBtn)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
alertDialog.show();
}
Run Code Online (Sandbox Code Playgroud)
布局对话.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/full_screen_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/frame">
<android.support.design.widget.FloatingActionButton
android:id="@+id/closeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_sky"
android:clickable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:drawable/ic_delete" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
样式.xml
<style name="full_screen_dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item …Run Code Online (Sandbox Code Playgroud) 我有一个警报对话框生成器,我在其中以编程方式定义布局。我有一个线性布局,我想为其设置一个属性,以便在运行时我可以更改应用程序的颜色主题。我已经完成了大部分工作,但我不知道如何进行线性布局,因为它没有在 xml 中定义。
我确实有一个十六进制颜色代码硬编码,但这不是我想要的。有没有办法设置像 ?attr/colorPrimary 这样的属性
alertAFFY = new AlertDialog.Builder(AddMakeActivity.this);
LinearLayout mainLayout = new
LinearLayout(AddMakeActivity.this);
mainLayout.setOrientation(LinearLayout.VERTICAL);
LinearLayout layoutTitle = new LinearLayout(AddAlarmActivity.this);
layoutTitle.setOrientation(LinearLayout.HORIZONTAL);
TextView title = new TextView(getApplicationContext());
title.setPadding(0, 30, 0, 30);
title.setTextColor(Color.parseColor("#FFFFFF"));
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
title.setText("Select One");
layoutTitle.setGravity(Gravity.CENTER_HORIZONTAL);
layoutTitle.addView(title);
**// i need to change the background color to take in ?attr/ **
layoutTitle.setBackgroundColor(Color.parseColor("#F8B195"));
layoutTitle.setMinimumHeight(20);
mainLayout.addView(layoutTitle);
Run Code Online (Sandbox Code Playgroud)
我正在尝试访问主题属性
<style name="Theme1" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/toolbarColor</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorDays">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
有没有办法为线性布局背景颜色设置属性?我需要它是动态的,这样我就可以在运行时更改它。它不能被硬编码在那里
我正在尝试更改单个选择 MaterialViewAlertDialog 中项目的文本颜色。我实现了更改“RadioButton”颜色和标题颜色,但无法更改项目的文本颜色。现在我使用以下样式:
<style name="AlertDialog" parent="ThemeOverlay.MaterialComponents.Dialog.Alert">
<item name="android:titleTextColor">@color/colorText</item>
<item name="android:textColorSecondary">@color/colorText</item>
<item name="android:textColorAlertDialogListItem">@color/colorText</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我还尝试使用 textAppearanceListItem 更改项目的文本颜色,但它不起作用。
android android-alertdialog material-design material-components material-components-android
我是颤振新手,我正在尝试将边框颜色添加到 AlertDialog 中。我找不到办法做到这一点,所以我尝试用容器替换它,但字体不一样,我找不到正确的字体。这是我试图复制的 AlertDialog。该字体与 FlatButton 标签使用的字体相同,但我仍然找不到它。
AlertDialog(
backgroundColor: Theme.of(context).primaryColor,
contentPadding: EdgeInsets.all(0),
title:Center(child:Text(contact.name + " "+ contact.familyName)),
content:Column(
children: <Widget>[
Text(_role,style: _style),
Divider(
color: Colors.blueGrey,
),
FlatButton.icon(
label: Text(
"Voir le profil",
),
icon:Icon(
Icons.account_circle,
color: Colors.black,
),
onPressed:(){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => UserProfileScreen(userId:contact.id)),
);
},
),
FlatButton.icon(
label: Text(
"Ajouter en ami",
style:TextStyle(color:Colors.green),
),
icon:Icon(
Icons.add,
color: Colors.green,
),
onPressed:()=>Navigator.pop(context,RoleActions.AJOUT_AMI),
),
_buildPermissions(),
],
),
),
Run Code Online (Sandbox Code Playgroud)
如何使标题、消息和按钮居中对齐
MaterialAlertDialogBuilder(requireContext())
.setTitle("Message")
.setMessage("This is info message.")
.setPositiveButton("Ok") { dialog, which ->
}
.show()
Run Code Online (Sandbox Code Playgroud) java android android-alertdialog kotlin material-components-android
我有一个AlertDialog盒子,用来获取用户的输入。但是,当用户在对话框外部单击时,无论用户是否已输入内容,它都会被忽略。
该输入对于应用程序中的进一步处理非常重要。所以我必须保留它。
只要能实现我的目的,我真的很欣赏不同的方法。
所以我在这里搜索了一些关于AlertDialog的问题,我不完全确定我在做什么,所以我很难将这些问题与我自己的例子联系起来.(我对这个整个Android编程还是新手,所以请耐心等待.)
我已经在public class _下定义了这个实现OnCLickListener的...
public AlertDialog myAlertDialog;
Run Code Online (Sandbox Code Playgroud)
然后我在onClick下有这个
public void onClick(View src) {
switch(src.getId()){
case R.id.buttonOk:
if (score==0){
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
myAlertDialog.setTitle("Title");
myAlertDialog.setMessage("Message");
myAlertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
} });
myAlertDialog.show();
}
Run Code Online (Sandbox Code Playgroud)
此行及其下方的行有错误:
myAlertDialog.setButton("OK", new DialogInterface.OnClickListener() {
Run Code Online (Sandbox Code Playgroud)
错误:
1st:此行的多个标记 - DialogInterface无法解析为类型 - 方法setButton(String,new OnClickListener(){})未定义类型
第二:DialogInterface无法解析为一个类型
任何人都可以告诉我,我做错了吗?
谢谢!