在看到这个功能的许多问题并尝试按照答案后,我想知道是否有更清晰的例子?
编辑:我试图制作一个大按钮,其图像和文字位于"中间".它必须表现为按钮(StateList drawable),图像/文本对应该分组并居中(作为一个组)
这就是我在故事板上的内容:

我想改变两个按钮图像.我有一个13x46的图像,但我在使用它作为按钮的图像时遇到了问题.我一直在寻找一些代码,但我对它们并不是很成功.
有任何想法吗?
我在标题div中有4个按钮.我已经将它们全部放在css的顶部和左边使用边距,所以它们在一行中彼此相邻.没有什么花哨.
现在,当按下按钮按钮文本向下移动一点时,我正在尝试执行操作.
我在CSS中使用此代码:
#btnhome:active{
line-height : 25px;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div id="header">
<button id="btnhome">Home</button>
<button id="btnabout">About</button>
<button id="btncontact">Contact</button>
<button id="btnsup">Help Us</button>
</div>
Run Code Online (Sandbox Code Playgroud)
按钮CSS示例:
#btnhome {
margin-left: 121px;
margin-top: 1px;
width: 84px;
height: 45px;
background: transparent;
border: none;
color: white;
font-size:14px;
font-weight:700;
}
Run Code Online (Sandbox Code Playgroud)
这些按钮也适用于标题背景,我确信它与这些设置有关:
#header {
background-image: url(images/navbar588.png);
height: 48px;
width: 588px;
margin: 2em auto;
}
Run Code Online (Sandbox Code Playgroud)
它运作良好但唯一的问题是所有其他按钮也将文本向下移动?这是为什么?我不清楚我只想使用#btnhome吗?所有按钮都有完全不同的ID.除边距外,所有按钮都具有相同的CSS设置.我需要编辑什么?
非常感谢你.
但是,测试一个简单的切换显示,第一次切换显示需要两次点击.之后它会在一个中完成.
<html>
<head>
<style>
#carousel{border:2px solid blue;
width:1280px;
height:720px;}
#p2{visibility:hidden;}
#p1{display:block;}
#btn{position:absolute;
top:2000px;}
</style>
<script src="mainScript.js"></script>
</head>
<body>
<div id="carousel">
<img id="p1" src="pic1.jpg">
<img id="p2" src="pic2.jpg">
</div>
<button type="button" id="button" onclick="clickEvent()">Click</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的javascript:
function clickEvent(){
var p = document.getElementById("p1");
if(p.style.display == "block")
p.style.display = "none";
else
p.style.display = "block";
}
Run Code Online (Sandbox Code Playgroud)
应该注意我没有使用jQuery,因为我发现的所有其他问题都与jQuery有关.
我需要帮助在运行时将按钮背景设置为默认全息黑暗.在编写布局时,可以使用很容易设置背景@android:drawable/btn_default_holo_dark,但是我找不到btn_default_holo_dark的相应可绘制id.android.R.drawable.btn_default_holo_dark不存在,android.R.drawable.btn_default并不适合全息黑暗主题.
为了解决这个问题,我希望你能告诉我按钮默认全息黑暗风格的正确ID,或者另一种简单的方法将按钮重置为默认主题样式(在我的情况下是全黑的).
我刚刚开始学习IOS开发.我花了好几天试图解决这个问题而且我无处可去.希望有人可以提供帮助.
我正在研究iPhone的计算器应用程序(仅用于练习).我创建了一个按钮网格,但是当我开始创建最后一行时,xCode在创建或移动每个按钮后不断崩溃.我最终创建了布局,但是当我运行应用程序时,按钮文本没有显示底行上的任何按钮(在IOS模拟器或我的iPhone上):
+----+ +----+ +----+ +----+ +----+
| 7 | | 8 | | 9 | | + | | - |
| | | | | | | | | |
+----+ +----+ +----+ +----+ +----+
+----+ +----+ +----+ +----+ +----+
| 4 | | 5 | | 6 | | / | | * |
| | | | | | | | | |
+----+ +----+ +----+ +----+ +----+
+----+ +----+ +----+ +----+ +----+
| 1 | …Run Code Online (Sandbox Code Playgroud) 我已经在RelativeLayout中创建了一个Button,我想设置它的大小.但我只能设置一个比原来更大的尺寸,例如我可以将其调整为200dp但不调整为20dp.
有解决方案吗?
这是我的代码
Button b = new Button(getApplicationContext());
myLayout.addView(b);
b.setWidth(200); // Work
b.setWidth(20); // Don't work
Run Code Online (Sandbox Code Playgroud)
谢谢
form1有一个button btnInvoke调用form2.form2包含a textbox和a button btn2.
用户必须输入数据textbox并按下btn2.
当btn2点击form2了发送textbox data来form1.
我试过通过构造函数,但我无法启动一个新的实例form1.
我该怎么办?
我尝试在按钮单击后将值设置为滑块,但它不起作用 - 滑块不移动.代码运行良好,没有错误.
它应该很简单,但我无法弄清楚.xCode版本4.5.2
谢谢!
我的代码:
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *debugLabel;
@property (weak, nonatomic) IBOutlet UISlider *slider;
- (IBAction)slider:(id)sender;
- (IBAction)ButtonChangeValue:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize slider;
...
- (IBAction)slider:(UISlider *)sender {
float value = [sender value];
self.debugLabel.text = [NSString stringWithFormat:@"Value: %f",value];
}
- (IBAction)ButtonChangeValue:(id)sender {
slider.value = 90;
}
Run Code Online (Sandbox Code Playgroud) 我有以下xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="20dip"
android:text="Fragment1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30dip" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button1"/>
<GridView
android:id="@+id/gridview"
android:layout_width="wrap_content"
android:layout_height="match_parent"overla
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
button1用于切换网格视图的可见性.但是,当网格视图不可见时,按钮不会填满屏幕.他们占据了屏幕的一半.当网格视图可见时,按钮占据了我想要的所有屏幕.我无法理解这种奇怪的行为.
android button android-layout android-linearlayout android-gridview