我试图在屏幕中间放置 6 个按钮,直到我向其中一个按钮添加文本后,它才起作用,如下图所示:
https://i.stack.imgur.com/1YSo0.jpg
这是导致问题的 2 个按钮的代码:
<LinearLayout
android:id="@+id/tableRow3"
android:padding="5dp"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/utilitiesButton"
android:layout_width="125dp"
android:layout_height="125dp"
android:layout_marginLeft="10dp"
android:background="@drawable/menu_sms"
android:gravity="bottom|right"
android:padding="10dp"
android:text="0"
android:textColor="@color/red"
android:textSize="40dp" />
<Button
android:id="@+id/statisticsButton"
android:layout_width="125dp"
android:layout_height="125dp"
android:layout_marginLeft="10dp"
android:background="@drawable/menu_statistics"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我需要将文本置于右下角。左侧按钮的文字大小越大,右侧按钮向下的程度就越深。对此有什么想法吗?
谢谢你,马吕斯
我在我的应用程序中使用 setColorFilter 来更改按钮的背景颜色。
这是我的代码:
// layout_main.xml
...
<Button
android:id="@+id/btn_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_round"
android:text="button"/>
...
Run Code Online (Sandbox Code Playgroud)
=================================================== ==
// btn_round.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:name="solid" android:color="#000000"/>
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
=================================================== ==
//MainActivity.java
...
Button btn_search = (Button)findViewById(R.id.btn_serach);
btn_search.getBackground().setColorFilter(Color.RED, Mode.MULTIPLY);
Run Code Online (Sandbox Code Playgroud)
我尝试了Mode.MULTIPLY和Mode.OVERLAY,结果是:

我期望有 ColorFilter 的效果,但它似乎隐藏在按钮后面。
这段代码在 Android 4.4 上运行良好。但是当我在Android 5.0上尝试时,它不起作用。
我怎么解决这个问题?
单击 WebView 页面内的链接或按钮时如何防止导航到另一个页面(我不想禁用触摸侦听器)。
我有一个名为 GameLoop 的 Activity(扩展 Activity 的类)。但我没有使用 xml 文件进行布局,而是使用一个类,因为我希望能够绘制到画布上。(我在一些教程上看到这是你应该做的)
布局类称为 GameLoopLayout。
我在布局类中运行了一个游戏循环,我可以将位图渲染到屏幕上并控制 FPS,一切都很好。但现在我想向其添加一个按钮,但由于我没有使用 xml 布局文件,所以我不知道该怎么做。有人可以帮我吗?
我在自动柜员机上做什么:
游戏循环布局:
Button button;
Canvas canvas;
SurfaceHolder surfaceHolder;
public GameLoopActivityLayout(Context context) {
//all necessary initializations here...
button = new Button(context);
button.setEnabled(true);
button.setLeft(10);
button.setTop(20);
}
//render function called during game loop
private void render() {
if (!surfaceHolder.getSurface().isValid())
return;
canvas = surfaceHolder.lockCanvas();
//draw all game objects to canvas...
button.draw(canvas);
surfaceHolder.unlockCanvasAndPost(canvas);
}
Run Code Online (Sandbox Code Playgroud) 我想在一个标签中显示来自用户的输入信息,但我在运行时无法在标签中显示性别选项
button.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
if (male.isSelected()) {
info.setText(male.getText());
}
if (female.isSelected()) {
info.setText(female.getText());
}
}
});
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
info.setText(nameField.getText()+ "\n"+ noField.getText() +"\n"+ emaileField.getText() );
}
});
Run Code Online (Sandbox Code Playgroud) 我想做一个简单的计算器,只对两个数字求和
var num1 = Number(document.getElementById("n1").value);
var num2 = Number(document.getElementById("n2").value);
function sum() {
var result = num1 + num2;
console.log(result);
}Run Code Online (Sandbox Code Playgroud)
<input type="text" id="n1">
<input type="text" id="n2">
<button id="btn" onclick="sum();">Submit</button>
<script src="javascript.js"></script>Run Code Online (Sandbox Code Playgroud)
当我运行它并添加两个值并按下按钮时,它在控制台中返回 0
我是 tkinter 的新手,我在使用 python GUI 上的按钮时遇到了问题。我创建了按钮及其背后的功能,但我无法单击该按钮。有人可以告诉我我做错了什么吗?用户界面出现了,我可以看到我无法点击的按钮。
import tkinter as tk
from tkinter import filedialog, Text
import os
#main
root = tk.Tk()
def addApp():
filename = filedialog.askopenfilename(initialir= "/", title= "Select File",
filetypes = (("executables", "*.exe"),
("all files", "*.*")))
canvas = tk.Canvas(root, height=700, width=700, bg="#33F9FF")
canvas.pack()
frame = tk.Frame(root, bg="white")
frame.place(relwidth=0.8, relheight=0.8, relx = 0.1, rely = 0.1)
openFile = tk.Button(root, text = "Open File", padx = 10, pady = 5, fg="black",
bg="#33F9FF", command="addApp")
openFile.pack()
runApps = tk.Button(root, text = "Run Apps", …Run Code Online (Sandbox Code Playgroud) 所以我很难对齐布尔玛专栏底部的按钮。
我希望按钮“购买”位于右栏的底部(与按钮“你好”并排)。我处于这种情况是因为我的其他专栏内容更长。
到目前为止,我在按钮上尝试了这些 CSS 样式(但没有一个对我有帮助):
vertical-align: bottom;
Run Code Online (Sandbox Code Playgroud)
margin-bottom: auto;
Run Code Online (Sandbox Code Playgroud)
position: absolute;
bottom: 0;
Run Code Online (Sandbox Code Playgroud)
这是我的 HTML:
<section class="section">
<div class="columns is-centered">
<div class="column is-one-fifth">
<h4 class="title is-4">I'm a big column</h4>
I'm taller than the column next to me so my column will be bigger, lorem ipsum lorem ipsum lorem ipsum lorem ipsum
<h6 class="sub">"lorem ipsum"</h6>
<button class="button is-fullwidth">Hello</button>
</div>
<div class="column is-one-fifth">
<h4 class="title is-4">I'm a small column</h4>
I'm a small column, and my button missplaced
<h6 class="sub">"lorem ipsum"</h6>
<button class="button …Run Code Online (Sandbox Code Playgroud) 我有给框阴影和填充的单元格编号,它看起来像一个按钮。由于它是可点击的,当“按钮”处于活动状态时,我更改了框阴影上的设置,因此看起来您确实在按下它。为此,当您单击/触摸时,它会按比例缩小一点,但会同时缩放数字和“按钮”。我想要做的是仅在活动时缩小数字,但我不知道如何。我试图将数字放在一个跨度中,但不适用于 :active 伪(我认为因为文本不可点击)。有没有其他方法或者我应该做一个按钮?
我给你代码和网页。代码会呈现得很糟糕,所以看看网页,看看单元格编号。(请在移动模式下检查它。我首先将其构建为移动设备,目前还没有媒体查询。) 网页在这里
.cellnumber {
/* box-shadow */
box-shadow: 5px 5px 10px white inset, -2px -2px 10px rgba(30, 30, 30, .5) inset;
padding: 10px 15px;
padding-bottom: 3px;
border-radius: 10px;
transition: all .35s;
}
.cellnumber:active {
box-shadow: 5px 5px 20px rgba(30, 30, 30, .3) inset, -5px -5px 20px rgba(90, 90, 90, .1) inset;
transform: scale(.97);
}
.paolo {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: 1px solid black;
padding: 30px 0;
padding-bottom: 55px;
margin-bottom: 50px; …Run Code Online (Sandbox Code Playgroud)我尝试在 myexcel 工作簿的不同工作表中的几个按钮上使用以下命令。
MsgBox (ActiveSheet.Shapes(Application.Caller).TopLeftCell.row)
Run Code Online (Sandbox Code Playgroud)
将这些按钮复制到我的工作簿的另一个区域时,我有时会遇到仍然显示原始按钮位置的行号的问题。作为下面屏幕截图中的示例,我单击底部的按钮,但它返回第 705 行而不是 739。谁能解释这种行为?