问题描述
public void Pop_Snack(String text) {
Snackbar snackbar = Snackbar.make( findViewById( android.R.id.content ),text,Snackbar.LENGTH_SHORT );
View sbView = snackbar.getView();
sbView.setBackgroundColor( getResources().getColor( R.color.colorPrimaryDark ) );
TextView tv = (snackbar.getView()).findViewById( com.google.android.material.R.id.snackbar_text );
Typeface font = ResourcesCompat.getFont( getBaseContext(),R.font.assistant );
tv.setTypeface( font );
tv.setTextSize( 14 );
snackbar.setAnchorView( findViewById( R.id.bottom_navigation ) );
snackbar.setDuration( 5000 );
snackbar.show();
}
但是,在某些情况下,我想从适配器使用此snackbar
。为了做到这一点,我尝试使用以下内容:
public void Pop_Snack(String text,View v,Context context) {
Snackbar snackbar = Snackbar.make( v.findViewById( android.R.id.content ),Snackbar.LENGTH_SHORT );
View sbView = snackbar.getView();
sbView.setBackgroundColor( context.getResources().getColor( R.color.colorPrimaryDark ) );
TextView tv = (snackbar.getView()).findViewById( com.google.android.material.R.id.snackbar_text );
Typeface font = ResourcesCompat.getFont( context,R.font.assistant );
tv.setTypeface( font );
tv.setTextSize( 14 );
snackbar.setAnchorView( v.findViewById( R.id.bottom_navigation ) );
snackbar.setDuration( 5000 );
snackbar.show();
}
问题是我遇到了以下错误:
java.lang.IllegalArgumentException: No suitable parent found from the given view. Please provide a valid view.
我尝试过类似的事情
Snackbar snackbar = Snackbar.make( v.findViewById(R.layout.activity_myitems),Snackbar.LENGTH_SHORT );
但我收到其他错误。
谢谢
解决方案:
更改为:
Snackbar snackbar = Snackbar.make( v,Snackbar.LENGTH_SHORT );
解决了问题。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)