【发布时间】:2018-07-01 08:45:32
【问题描述】:
正在使用支持库测试 Android 的可下载字体的新功能。
让它在我的文本视图和自定义对话框的整个应用程序中工作,但是当尝试将它用作 Snackbar 中的自定义字体时,它使应用程序崩溃。我在 OnClick 对话框中的用法是这样的。
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), R.string.snackbar_confirm_removal_or_wait, Snackbar.LENGTH_LONG)
.setAction(R.string.snackbar_delete, new View.OnClickListener() {
@Override
public void onClick(View view) {
String quote = quotes.get(position).quote;
deleteEntry(quote);
quotes.remove(position);
adapter.notifyDataSetChanged();
Snackbar.make(findViewById(android.R.id.content), R.string.snackbar_deleted, Snackbar.LENGTH_SHORT)
.setDuration(1000)
.show();
}
})
.setDuration(8500)
.setActionTextColor(ContextCompat.getColor(QuoteActivity2.this, R.color.snackbar_varning_red));
TextView textView = (mSnackbar.getView()).findViewById(android.support.design.R.id.snackbar_text);
Typeface typeface = ResourcesCompat.getFont(QuoteActivity2.this, R.font.roboto_slab);
textView.setTypeface(typeface);
snackbar.show();
我的 logcat 给出了特定崩溃的以下输出
E/AndroidRuntime(24199): java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.support.design.widget.BaseTransientBottomBar.getView()' on a null object reference
关于如何解决它或将可下载字体用作带有小吃栏的自定义字体有什么想法吗?
【问题讨论】:
标签: android android-layout android-support-library android-snackbar android-downloadable-fonts