【问题标题】:How to use button styling-selectors in NativeScript如何在 NativeScript 中使用按钮样式选择器
【发布时间】:2017-09-18 10:11:30
【问题描述】:

我有一个 NativeScript 应用程序正在运行,现在我想更改按钮按下时的背景颜色(以便用户可以看到他确实按下了它)。经过一番谷歌搜索,我发现documentation。所以我尝试将这些应用到我的代码中(遗憾的是我没有通过 TS 初始化我的按钮,所以我不能使用 btn = new buttonModule.Button(); 行。

我的html:

<Button [text]="'SIGNIN'|translate" (onTap)="passCredentials()"></Button>

我的 CSS:

Button {
    background-color: rgba(255, 230, 0, 1);
    font-weight: bold; 
    margin-left: 10;
    margin-right: 10;
    padding: 10;
    height: 50;
    margin-top: 30;
    margin-bottom: 25;
}
Button:pressed {
    background-color: red;
}

这就是我尝试过的,但他既没有抛出错误也没有改变背景颜色。我需要手动告诉他在这些课程之间切换吗?我怎么能这样做?

【问题讨论】:

    标签: javascript html css typescript nativescript


    【解决方案1】:

    试试highlighted 伪选择器:

    Button:highlighted{
        background-color: red;
    }
    

    【讨论】:

    • 到目前为止突出显示的“工作”,一旦按下一会儿它就会改变颜色。如果在很短的时间内点击它,它不会改变。仍然对一些人来说。这可能是一个合法的解决方法,谢谢:)
    【解决方案2】:

    不用自己写css就可以用NativeScript core theme.
    将核心主题之一添加到您的 app.css 文件中,然后您可以将 btnbtn-primary 类添加到您的 Button 组件中。 在这里我分享链接以供参考,以将核心主题导入您的app.css

    Color Schemes

    【讨论】:

      猜你喜欢
      • 2019-01-16
      • 2012-02-03
      • 2015-09-21
      • 2016-03-16
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多