在我的 AlertDialog 中,我的肯定按钮和否定按钮是“附加的”。我很确定他们之间应该有差距。有人能告诉我为什么会这样吗?我很乐意提供任何代码。 Here is what my AlertDialog looks like.
我有一个用于正文的自定义 View 以及我的 AlertDialog 的标题(我不会发布该 XML 代码,因为我认为没有必要,但请告诉我。)在 MainActivity 中,我膨胀我的自定义标题和正文 View ,并覆盖 setPositive() 和 setNegative(),然后我使用 onShow() 自定义按钮的颜色。
对于复杂的代码,我们深表歉意,但我们将不胜感激 :)。这是我的 MainActivity:
public void openPrompt(View view){
//builds and opens custom view with prompt.XML
LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
EditText input = (EditText)promptView.findViewById(R.id.userInput);
builder.setCancelable(true).setView(R.layout.customdialoglayout)
.setNegativeButton("One", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"CANCEL clicked",Toast.LENGTH_SHORT).show();
}
})
.setPositiveButton("Two", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"SET clicked",Toast.LENGTH_SHORT).show();
}
});
//set title with custom XML layout view
LayoutInflater inflater = getLayoutInflater();
View titleView = inflater.inflate(R.layout.cutomtitlebar,null);
builder.setCustomTitle(titleView);
AlertDialog ad = builder.create();
//change colors of background and buttons
ad.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Context context = MainActivity.this;
Window view = ((AlertDialog)dialog).getWindow();
view.setBackgroundDrawableResource(R.color.colorPrompt);
Button negButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negButton.setBackgroundColor(context.getResources().getColor(R.color.colorPromptButton));
negButton.setTextColor(context.getResources().getColor(R.color.colorPromptButtonText));
Button posButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
posButton.setBackgroundColor(context.getResources().getColor(R.color.colorPromptButton));
posButton.setTextColor(context.getResources().getColor(R.color.colorPromptButtonText));
}
});
ad.show();
}
编辑 这是我用于 setView() 的 XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="CUSTOM TEXT"
android:id="@+id/textView3"
android:layout_gravity="center"/>
最佳答案
如果我们需要在您的按钮之间留出间隙,我们为什么不即兴发挥呢?您可以使用中性按钮而不是使用否定按钮。这是因为正面和负面是密不可分的,但是中性和正面在最右侧和最左侧都可以正常工作。所以只需将否定按钮更改为中立即可。见下面的代码:
AlertDialog.Builder builder = new AlertDialog.Builder(preview.this);
builder.setTitle("Title here");
builder.setMessage("message on dialog here");
builder.setCancelable(true);
builder.setNeutralButton("Name of button N", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//your code here
}
});
builder.setPositiveButton("Name of button P", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//your code here
}
});
这是一个非常适合我的示例,您可以根据您的代码对其进行如下编辑:
builder.setCancelable(true).setView(R.layout.customdialoglayout)
.setNeutralButton("One", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"CANCEL clicked",Toast.LENGTH_SHORT).show();
}
})
.setPositiveButton("Two", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"SET clicked",Toast.LENGTH_SHORT).show();
}
});
关于android - 为什么我的两个 AlertDialog 按钮之间没有间隙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37951871/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput