标签: button

如何居中对齐按钮文本 (Jetpack Compose)

我试图将按钮的文本垂直和水平居中对齐,默认情况下不存在。我尝试使用“偏移”来定位按钮中的文本,但在各种设备尺寸上定位并不一致。

我的按钮的代码是:

                Button(
                onClick = {
                    navController.navigate("fourth_screen")
                },
                modifier = Modifier.constrainAs(buttonSave) {
                    top.linkTo(glButtonSaveTop)
                    bottom.linkTo(glButtonSaveBottom)
                    start.linkTo(glLeft)
                    end.linkTo(glRight)
                    width = Dimension.fillToConstraints
                    height = Dimension.fillToConstraints

                },
                enabled = !errorMsg.value,
                colors = if (query.value.text != ""){
                    ButtonDefaults.
                    buttonColors(backgroundColor = colorResource(id = R.color.voodlee_red))}
            else {
                    ButtonDefaults.
                    buttonColors(backgroundColor = colorResource(id = R.color.gray))}

            ) {
                Text(
                    "Save", color = colorResource(id = R.color.dark_blue),
                    fontSize = with(LocalDensity.current) {
                        dimensionResource(id = R.dimen._16ssp).toSp()
                    },
                    fontFamily = FontFamily(Font(R.font.poppins_medium)),
                    textAlign = TextAlign.Center,
                    modifier = Modifier.fillMaxSize().offset(y= (0.15).dp)) //offset for positioning

            }
Run Code Online (Sandbox Code Playgroud)

如何使按钮中的文本垂直和水平居中,以适应所有设备尺寸。

编辑:在稳定的 Jetpack …

android button android-jetpack-compose

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

如何使用javascipt切换Bootstrap 5选项卡(按钮版本)

我想对开关选项卡进行编程(使用 bootstrap 5)。Bootsrap 文档说:

作为最佳实践,我们建议使用选项卡元素,因为这些是触发动态更改的控件,而不是导航到新页面或位置的链接。

所以我想使用按钮而不是链接。代码:

$("#mybut").click(function() {
  var sel = document.querySelector('#nav-tab-manager')
  bootstrap.Tab.getInstance(sel).show()
})
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav>

<div class="nav nav-tabs" id="nav-tab" role="tablist">
  <button class="nav-link active" id="nav-tabs-order" data-bs-toggle="tab" data-bs-target="#tabs-1" type="button" role="tab" aria-controls="tabs-1" aria-selected="true">Orders
  </button>
  <button class="nav-link" id="nav-tab-manager" data-bs-toggle="tab" data-bs-target="#tabs-2" type="button" role="tab" aria-controls="tabs-2" aria-selected="false">Managers
  </button>
  </div>
</nav>


<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active" id="tabs-1" role="tabpanel" aria-labelledby="tabs-tab1">
    Orders
  </div>
  <div class="tab-pane fade" id="tabs-2" role="tabpanel" aria-labelledby="tabs-2">
    Managers
  </div>
</div>

<button type="button" class="btn btn-primary" id="mybut">Want switch to manager</button> …
Run Code Online (Sandbox Code Playgroud)

javascript tabs button twitter-bootstrap bootstrap-5

1
推荐指数
1
解决办法
2611
查看次数

Discord JS,discord 按钮;如何在消息中附加超过 5 个按钮?

如何使用discord-buttons、discord.js 将超过 5 个按钮附加到消息中?

\n

例子

\n

我尝试的方式:

\n
let Buttons = [];\n    Buttons[0] = new discordButton.MessageButton().setStyle(\'gray\').setID("0").setLabel(\' \');\n    Buttons[1] = new discordButton.MessageButton().setStyle(\'gray\').setID("1").setLabel(\' \');\n    Buttons[2] = new discordButton.MessageButton().setStyle(\'gray\').setID("2").setLabel(\' \');\n\n    Buttons[3] = new discordButton.MessageButton().setStyle(\'gray\').setID("3").setLabel(\' \');\n    Buttons[4] = new discordButton.MessageButton().setStyle(\'gray\').setID("4").setLabel(\' \');\n    Buttons[5] = new discordButton.MessageButton().setStyle(\'gray\').setID("5").setLabel(\' \');\n    \n    Buttons[6] = new discordButton.MessageButton().setStyle(\'gray\').setID("6").setLabel(\' \');\n    Buttons[7] = new discordButton.MessageButton().setStyle(\'gray\').setID("7").setLabel(\' \');\n    Buttons[8] = new discordButton.MessageButton().setStyle(\'gray\').setID("8").setLabel(\' \');\n\nmsg.channel.send(`\xe2\x81\xa3...`, { buttons:Buttons });\n
Run Code Online (Sandbox Code Playgroud)\n

它得到的错误:

\n
DiscordAPIError: Invalid Form Body\ncomponents[0].components[5]: The specified component exceeds the maximum width\ncomponents[0].components[6]: The specified component exceeds …
Run Code Online (Sandbox Code Playgroud)

javascript button discord

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

如何使用 Angular 中的添加按钮添加输入字段?

因此,我有一个现有的乘客详细信息输入字段(姓名、地址、号码、电子邮件)。我想做的是使用添加按钮添加另一个乘客详细信息输入。到目前为止,这是我的按钮代码:

<div class="center">
          <button
          type="button"
          class="next-button"
          mat-flat-button
          matTooltip="Add new passenger"
          matTooltipClass="tooltipClass"
          matTooltipPosition="below"
          (click)=""
        >
          <mat-icon>add</mat-icon>
        </button>
Run Code Online (Sandbox Code Playgroud)

这是我的输入字段的示例图像。 正如您所看到的,下面是一个添加按钮,允许用户添加新乘客。

input button addition angular mat-icon

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

按钮图像上的中心标题

我想以编程方式更改按钮图像和标题。当在故事板上设计按钮图像和标题(普通)时,它居中没有问题。但是当\xc4\xb1使用时;

\n
  startButton.setImage(UIImage(named: "StartButton"), for: .normal)\n  startButton.setAttributedTitle(NSAttributedString(string: "START"), for: .normal)\n
Run Code Online (Sandbox Code Playgroud)\n

以编程方式更改按钮图像和标题。按钮标题未位于图像中心。看起来它位于图像的左侧。

\n

button ios swift

1
推荐指数
1
解决办法
137
查看次数

在 PySimpleGui 中创建自定义按钮

我正在使用 PySimpleGui 制作一个 GUI,我希望我的一个按钮是一个圆圈,一个更大。有没有办法做到这一点?如果是这样,怎么办?我正在使用 TKinter 端口。

python user-interface tkinter button pysimplegui

1
推荐指数
1
解决办法
5686
查看次数

使用 MUI v5 实现深色模式

在 v5 中,尝试创建一个从深色模式切换到浅色模式的切换对我来说相当困难。

直接使用来自 MUI Sandbox MUI darkmode的代码,我尝试将代码分离以在 app.js 和我的 Navbarpractice.js 中工作。

应用程序.js

import React from "react";
import useMediaQuery from '@mui/material/useMediaQuery';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import { Paper } from "@mui/material";
import BasicCard from "./components /Card.js";
import Navbarpractice from "./components /Navbar/Navbarpractice"

const ColorModeContext = React.createContext({ toggleColorMode: () => {} });


function App() {
  const [mode, setMode] = React.useState('light');
  const colorMode = React.useMemo(
    () => ({
      toggleColorMode: () => {
        setMode((prevMode) => (prevMode …
Run Code Online (Sandbox Code Playgroud)

button reactjs material-ui darkmode lightmode

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

在我的 Mac 应用程序中,如何使用 SwiftUI 按钮打开本地 PDF 文件?

在我的 Mac 应用程序中,我想在点击按钮时通过新视图显示本地 PDF 文件。StackOverflow 帖子(此处)展示了如何使用 UIViewRepresentable 对 iOS 应用程序执行此操作,但这不适用于 Mac 应用程序。

pdf macos button swiftui

1
推荐指数
1
解决办法
1129
查看次数

我是否需要将“onKeyDown”添加到“button”以实现辅助功能合规性?(WCAG 2.0)

我有一个按钮,点击后会展开一张包含更多信息的卡片

我需要添加onKeyDown以button确保可访问性合规性吗?

或者这是多余的,因为该元素已经是 a button?

我还缺少其他需要遵守的内容WCAG 2.0吗?

这是我的可折叠按钮代码react

const ariaPressed = checked ? "true" : "false";

return (
  <button
    tabIndex={0}
    role="button"
    component="button"
    aria-pressed={ariaPressed}
    aria-expanded={ariaPressed}
    onClick={toggleChecked}
  >
    {checked ? "Hide Versions" : "View Versions"}
  </button>
);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在此输入图像描述

accessibility button wcag reactjs wcag2.0

1
推荐指数
1
解决办法
570
查看次数

按钮副标题标签

有一天,我在故事板中制作了带有标题标签、副标题标签和图像的按钮,并得到了这种效果

故事板中按钮的图像

但现在当我尝试在代码中以编程方式执行此操作时,我遇到了问题,我看不到字幕..

private var firstPaidPack: UIButton = {
        let button = UIButton(type: .custom)
        let image = UIImage(systemName: "circle")
        button.layer.cornerRadius = 15
        button.backgroundColor = UIColor(white: 1, alpha: 0.3)
        button.setImage(image, for: .normal)
        button.setTitle("1.99$", for: .normal)
        button.subtitleLabel?.textAlignment = .center
        button.subtitleLabel?.text = "subtitle text to check how it..."
        button.titleLabel?.font = UIFont(name: "Arial", size: screenWidth / 375 * 19)
        return button
    }()
Run Code Online (Sandbox Code Playgroud)

button swift

1
推荐指数
1
解决办法
1987
查看次数