Android,按钮视图.Button大小为38x38dp,文本大小为20dp(只有一个+字符的文本).重力设定为中心.
文本不是垂直居中的.根据Android的内部会计,文本对于指定的按钮大小来说太大,因此文本的顶部与顶部填充对齐,底部被切掉.那不是我想要的; 我希望文本在顶部和底部均匀切割.换句话说,垂直居中.加号字符,因为它需要少于一个完整大小的字符单元格,所以不会受此影响.
这Gravity是我设定的,而不是Layout gravity.我知道不同之处.
任何想法如何在这样的条件下使垂直居中工作,而不是覆盖draw()?
我将事件绑定<Return>到一个Button,认为这会导致command在命中之后运行Enter:
Button(self.f, text="Print", command=self.Printer).pack(side=RIGHT, padx=10, pady=10)
self.button1 = Button(self.f, text="search", command=self.search)
self.button1.bind('<Return>', self.search)
self.button1.pack(side=RIGHT, padx=10, pady=10)
Run Code Online (Sandbox Code Playgroud)
但它没有做任何事情.按下self.search时我必须做什么才能运行Enter?
我有这个功能
$("a#<?php echo $custom_jq_settings['toggle']; ?>").click(function() {
jQuery("#<?php echo $custom_jq_settings['div']; ?>").slideToggle(400);
jQuery("#featurepagination").toggle();
jQuery("#featuretitlewrapper").toggle();
return false;
});
Run Code Online (Sandbox Code Playgroud)
这是我想在页面加载时触发的按钮
<a href="#" id="featuretoggle" onclick="changeText('<?php if (is_front_page()) {?>Show<?php } else { ?>Show<?php } ?> Features');"><?php if (is_front_page()) {?>Hide<?php } else { ?>Hide<?php } ?> Features</a>
Run Code Online (Sandbox Code Playgroud)
我想在页面加载时触发该按钮,以便它开始打开但随后滑动/关闭
我的程序中有两个单选按钮,但是当我运行它时,它们都没有被检查,我希望默认情况下检查其中一个,我怎样才能实现这一点?
<li><input type="radio" name="r1" value="o" onClick="submit();" <?php echo ($_SESSION['r1'] == "o") ? 'checked="checked"' : ''; ?> />On</li>
<li><input type="radio" name="r1" value="p" onClick="submit();" <?php echo ($_SESSION['r1'] == "p") ? 'checked="checked"' : ''; ?> />Off</li>
Run Code Online (Sandbox Code Playgroud)
我希望第一次打开页面时检查"打开"按钮
我正在制作游戏,我有一个选项页面可以打开或关闭音乐.我想覆盖后退按钮,以便它返回到主页,你会明白为什么当你看到我的代码时:
public class OptionsActivity extends Activity {
private boolean isMyServiceRunning(String serviceCanonicalClassName) {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceCanonicalClassName.equals(service.service.getClassName())) {
return true;
}
}
return false;
}
Intent i; // Handles MyMusicService.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.options);
final TextView tSound = (TextView) findViewById(R.id.textView2);
final Button saveBtn = (Button) findViewById(R.id.optSaveBtn);
final Button tblBtn = (Button) findViewById(R.id.tableBtn);
i=new Intent(this, MyMusicService.class);
final ToggleButton soundOption = (ToggleButton) findViewById(R.id.soundPref);
boolean musicPlays = isMyServiceRunning(MyMusicService.class.getCanonicalName());
soundOption.setChecked(musicPlays);
if(musicPlays==true){
tSound.setText("On");
} …Run Code Online (Sandbox Code Playgroud) 这是一个非常基本的问题,但我相信那里有人知道为什么.在HTML中,当我单独创建一个按钮元素,并且不给它onclick并且没有jQuery时.click(),按钮将不执行任何操作.完善.但是当我这样做但是<form>元素内的按钮时,它会尝试将所有表单元素的GET数据发送到我网站的根地址?它为什么这样做?我没有把它作为提交按钮,甚至没有定义method或action在那个表格?
提前感谢您的信息!
**编辑**
这就是我为解决问题所做的工作.对于里面的按钮<form>,使用:
<button type="button"></button>
Run Code Online (Sandbox Code Playgroud)
默认情况下它不会做任何事情.
我陷入了Android的一个奇怪问题 - 我希望有一个看起来像这样的按钮:
|-----------------------------------------------------------------------|
| [icon] <5px> [text text text] |
|-----------------------------------------------------------------------|
Run Code Online (Sandbox Code Playgroud)
并且组([icon] <5px> [文本文本文本])应居中.请注意,5px仅用作占位符,用于图标和文本之间的任何填充
我在这里找到了一些答案或多或少地围绕设置背景(我不想做因为我有另一个背景)或使用android:drawableLeft属性来设置图标.
但是看起来像setCompoundDrawablesWithIntrinsicBounds方法的文档有点误导(见这里).它声明图像位于TEXT的左/右/上/下侧,这是不正确的.图标位于按钮的相应侧.例如:
设置android:drawableLeft属性将图标放在最左边的位置并获取此信息(使用重力CENTER):
|-----------------------------------------------------------------------|
| [icon] [text text text] |
|-----------------------------------------------------------------------|
Run Code Online (Sandbox Code Playgroud)
或者这个(重力为左):
|-----------------------------------------------------------------------|
| [icon] [text text text] |
|-----------------------------------------------------------------------|
Run Code Online (Sandbox Code Playgroud)
两个都是丑陋的地狱:(
我找到了一个看起来像这样的解决方法:
public static void applyTextOffset(Button button, int buttonWidth) {
int textWidth = (int) button.getPaint().measureText(button.getText().toString());
int padding = (buttonWidth / 2) - ((textWidth / 2) + Constants.ICON_WIDTH + Constants.ICON_TO_TEXT_PADDING);
button.setPadding(padding, 0, 0, 0);
button.setCompoundDrawablePadding(-padding);
}
Run Code Online (Sandbox Code Playgroud)
它或多或少有效,但由于以下原因,我不喜欢它:
难道没有更优雅的解决方案吗?
第一项活动是用户保存其详细信息.单击保存按钮后,Alertdialog询问确定或取消.如果用户点击确定,则开始新活动.
protected final Dialog onCreateDialog(final int id) {
Dialog dialog = null;
switch(id) {
case DIALOG_ID:
AlertDialog.Builder builder = new AlertDialog.Builder(AppointInformation.this);
builder.setMessage("Information saved successfully ! Add Another Info?")
.setCancelable(false)
.setPositiveButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(((Dialog)dialog).getContext(),CheckPatient.class));
}
})
.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
dialog = alert;
break;
default:
}
return dialog;
}
Run Code Online (Sandbox Code Playgroud) 我有以下课程
public class GameActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View gameView = new GameView(this);
setContentView(gameView);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想在我的GameView类中添加一个Button.
public GameView(Context context) {
super(context);
// Code ...
}
Run Code Online (Sandbox Code Playgroud)
我在游戏过程中需要这个按钮,所以它应该是所有其他画布前面的'我正在画画.
我怎样才能做到这一点?
我正在pygame制作一个游戏,在第一个屏幕上我希望有按钮可以按下(i)启动游戏,(ii)加载带有说明的新屏幕,以及(iii)退出程序.
我已经在网上找到了这个用于按钮制作的代码,但我并不是真的理解它(我在面向对象编程方面并不擅长).如果我能得到一些关于它正在做什么的解释那将是伟大的.此外,当我使用它并尝试使用文件路径在我的计算机上打开文件时,我得到错误sh:filepath:权限被拒绝,我不知道如何解决.
#load_image is used in most pygame programs for loading images
def load_image(name, colorkey=None):
fullname = os.path.join('data', name)
try:
image = pygame.image.load(fullname)
except pygame.error, message:
print 'Cannot load image:', fullname
raise SystemExit, message
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect()
class Button(pygame.sprite.Sprite):
"""Class used to create a button, use setCords to set
position of topleft corner. Method pressed() returns
a boolean and should be called inside …Run Code Online (Sandbox Code Playgroud)