【问题标题】:Changing snackbar typeface in androidx在 androidx 中更改快餐栏字体
【发布时间】:2019-06-25 18:32:05
【问题描述】:

在迁移到 androidx 之前,我使用此代码更改了小吃栏文本的字体:

Snackbar snackbar = Snackbar.make(main_Coordinator, "No Connection", Snackbar.LENGTH_INDEFINITE);
                View view = snackbar.getView();
                TextView textView = view.findViewById(android.support.design.R.id.snackbar_text);
                textView.setTypeface(Typeface.createFromAsset(getAssets(), "Shabnam.ttf"));

但在迁移到 androidx 后,我收到了错误的快餐栏文本 ID android.support.design.R.id.snackbar_text 它说 Cannot resolve symbol design

我也在使用新的设计库com.google.android.material:material:1.0.0

有什么帮助吗?

【问题讨论】:

    标签: android androidx android-snackbar


    【解决方案1】:

    只需像这样引用新的设计库 -

    Snackbar snackbar = Snackbar.make(main_Coordinator, "No Connection", Snackbar.LENGTH_INDEFINITE);
                View view = snackbar.getView();
                TextView textView = view.findViewById(com.google.android.material.R.id.snackbar_text);
                textView.setTypeface(Typeface.createFromAsset(getAssets(), "Shabnam.ttf"));
    

    【讨论】:

      【解决方案2】:

      使用com.google.android.material.R.id.snackbar_text

      您已迁移到 AndroidX,这意味着该库现在有所不同。因此,您引用的 R 需要来自新库而不是旧库。

      【讨论】:

        猜你喜欢
        • 2017-05-22
        • 2017-02-04
        • 2016-08-12
        • 2017-11-10
        • 2014-11-22
        • 2018-06-03
        • 2018-02-13
        • 2016-07-04
        • 1970-01-01
        相关资源
        最近更新 更多