标签: button

按钮和输入之间的区别?

可能重复:
<button>与<input type ="button"/>.哪个用?

<button type="button" name="theButton">SUBMIT</button>和之间是否有任何重大差异<input type="submit" value="SUBMIT" name="theButton" />

还有,你能用<button type="submit" name="theButton">SUBMIT</button>吗?

html forms input submit button

28
推荐指数
1
解决办法
2万
查看次数

如何设置按钮的大小?

我把我的按钮放在带有GridLayout的JPane中.然后我将JPanel放入另一个带有BoxLayout.Y_AXIS的JPanel中.我希望GridLayout中的按钮是方形的.我使用tmp.setSize(30,30)并且它不起作用.我也尝试使用,new GridLayout(X, Y, 4, 4)但我无法弄清楚X和Y是什么.那么,做这些事情的正确方法是什么?

添加:

我仍然无法解决问题.这是我想要做的代码:

import javax.swing.*;
import java.awt.*;

public class PanelModel {
    public static void main(String[] args) {
        JFrame frame = new JFrame("Colored Trails");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

        JPanel firstPanel = new JPanel();
        firstPanel.setLayout(new GridLayout(4, 4));
        JButton btn;
        for (int i=1; i<=4; i++) {
            for (int j=1; j<=4; j++) {
                btn = new JButton();
                btn.setPreferredSize(new Dimension(100, 100));
                firstPanel.add(btn);
            }
        }

        JPanel secondPanel = new JPanel();
        secondPanel.setLayout(new GridLayout(5, 13));
        for (int …
Run Code Online (Sandbox Code Playgroud)

java size user-interface swing button

27
推荐指数
2
解决办法
31万
查看次数

自定义Android Toast中的按钮?

是否可以在Toast中使用按钮?

从理论上讲,是的,因为您可以使用XML中的布局构建自定义Toast,但我尝试在其中放置一个按钮,但无法使其注册单击.有没有人设法做那样的事情?

android button toast android-button

27
推荐指数
4
解决办法
3万
查看次数

动态创建按钮并设置onClickListener

我在Android上处理动态创建的按钮时遇到问题.我正在创建N个按钮,单击按钮时我必须执行相同的方法,但我必须知道单击了哪个按钮.

for (int i = 0; i < NO_BUTTONS; i++){
        Button btn = new Button(this);
        btn.setId(2000+i);

        ...

        btn.setOnClickListener((OnClickListener) this);
        buttonList.addView(btn);
        list.add(btn);
Run Code Online (Sandbox Code Playgroud)

目前我正在为每个按钮添加ID,我正在使用下面的方法查看单击了哪个按钮.(行btn.setId(2000+i);和btn.setOnClickListener((OnClickListener) this);).此方法也在活动中实现.

@Override
public void onClick(View v) {
    switch (v.getId()){
        case 2000: selectButton(0);
        break;

        ...

        case 2007: selectButton(7);
        break;
    }
 }
Run Code Online (Sandbox Code Playgroud)

这对我来说不太好看,所以我想问有没有更好的方法呢?或者如何向onclick事件发送一些信息?有什么建议?

android button android-widget android-layout

27
推荐指数
3
解决办法
5万
查看次数

事件OnClick用于自定义通知中的按钮

我有一个带按钮的自定义通知.要设置通知并使用事件OnClick on my button,我使用了以下代码:

//Notification and intent of the notification 
Notification notification = new Notification(R.drawable.stat_notify_missed_call,
            "Custom Notification", System.currentTimeMillis());

Intent mainIntent = new Intent(getBaseContext(), NotificationActivity.class);
PendingIntent pendingMainIntent = PendingIntent.getActivity(getBaseContext(),
    0, mainIntent , 0);
notification.contentIntent = pendingMainIntent;

//Remoteview and intent for my button
RemoteViews notificationView = new RemoteViews(getBaseContext().getPackageName(),
    R.layout.remote_view_layout);

Intent activityIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:190"));
PendingIntent pendingLaunchIntent = PendingIntent.getActivity(getBaseContext(), 0,
            activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

notificationView.setOnClickPendingIntent(R.id.button1,
    pendingLaunchIntent);

notification.contentView = notificationView;

notificationManager.notify(CUSTOM_NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)

使用此代码,我使用自定义布局自定义通知...但我无法单击按钮!每次我尝试单击按钮时,我都会单击整个通知,因此脚本会启动"mainIntent"而不是"activityIntent".

我在互联网上看到这段代码不适用于所有终端.我已经在模拟器和HTC Magic上尝试过但我总是遇到同样的问题:我无法点击按钮!

我的代码是对的?有人可以帮帮我吗?

谢谢,

西蒙娜

notifications android onclick button

27
推荐指数
2
解决办法
4万
查看次数

如何将Button的背景恢复为默认(以编程方式)?

所以我设置了一个按钮的背景:

b.setBackgroundResource(R.drawable.custom_button1);
Run Code Online (Sandbox Code Playgroud)

如何以编程方式将其设置回默认(无聊的灰色)Android按钮?是否有我自己可以参考的R.android.boring_grey资源标识符而不重新创建这些状态?似乎无法找到它.也许我的谷歌搜索技能让我失望了.

哦,顺便说一句,我试过这个:

   b.setBackgroundResource(0);
Run Code Online (Sandbox Code Playgroud)

按钮实际上消失了(与黑色背景混合?).

android button

27
推荐指数
3
解决办法
2万
查看次数

如何通过代码设置按钮背景图像

我正在Button使用以下代码创建

LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);

Button btn = new Button(this);
btn.setOnClickListener(newtodobtn);
btn.setText("New Todo");

btn.setBackgroundDrawable(new Button(this).getBackground());

ll.addView(btn);
Run Code Online (Sandbox Code Playgroud)

我在路径中有一个图像@drawable/new_todo_image设置为按钮的背景.如何以Button编程方式将其设置为?

java android button

27
推荐指数
2
解决办法
5万
查看次数

如何检测"最近的应用程序"系统按钮点击(Honeycomb +)

我想知道这个按钮调用的方法.

在此输入图像描述

我的游戏总是暂停/继续正常除当我使用这个按钮,它看起来像这个按钮不会调用onPause()和onResume()一个方法活动.它可以工作,如果我退出游戏,转到另一个窗口(如图片中的那个),然后使用此按钮恢复.但是,如果我只是按下这个按钮,当游戏时,游戏暂停,但线程dosnt恢复就像它每隔一段时间一样,游戏类型只是停留在屏幕上并且有点闪烁.

很难解释,但我希望我有点清楚,如果没有,请问!

user-interface android button android-3.0-honeycomb android-4.0-ice-cream-sandwich

27
推荐指数
3
解决办法
2万
查看次数

使图像像按钮一样

我正在制作一个简单的HTML页面,我有这个图像,我想充当一个按钮.

这是我的图像的代码:

<div style="position: absolute; left: 10px; top: 40px;"> 
    <img src="logg.png" width="114" height="38">
</div>
Run Code Online (Sandbox Code Playgroud)

基本上我想在其中添加此功能:

<div>
    <input id="saveForm" name="saveForm" class="btTxt submit" type="submit" value="Submit"/>
</div>
Run Code Online (Sandbox Code Playgroud)

由于我的图像具有所需的文本,因此不需要按钮本身上显示提交的文本.

无论如何,这可能吗?如果是的话,怎么样?:)

html image button

27
推荐指数
2
解决办法
17万
查看次数

Chrome扩展弹出窗口无效,点击事件无法处理

我创建了一个JavaScript变量,当我点击按钮时它应该增加1,但它没有发生.

这是manifest.json.

{
  "name":"Facebook",
  "version":"1.0",
  "description":"My Facebook Profile",
  "manifest_version":2,
  "browser_action":{
    "default_icon":"google-plus-red-128.png",
    "default_popup":"hello.html"
  }
}
Run Code Online (Sandbox Code Playgroud)

这是html页面的代码

<!DOCTYPE html>
<html>
<head>
<script>
var a=0;
function count()
{
  a++;
  document.getElementById("demo").innerHTML=a;
  return a;
}
</script>
</head>
<body>
<p id="demo">=a</p>
<button type="button" onclick="count()">Count</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我希望扩展程序向我显示a的值,并在每次单击扩展名或按钮时将其递增1

扩展的图片

javascript google-chrome button google-chrome-extension content-security-policy

27
推荐指数
1
解决办法
4万
查看次数