我有,我想刪除TextView的,但是當我使用View.INVISIBLE那麼它沒有顯示UO但使用View.GONE時則應用程序是說NullPointerException異常崩潰的小吃店。爲什麼這樣?爲什麼View.Gone不是在小吃吧工作?
下面是代碼
MainActivity.java
Snackbar sk=Snackbar.make(findViewById(R.id.ll),"It is checked",Snackbar.LENGTH_INDEFINITE);
sk.setAction("Undo",m);
sk.setActionTextColor(Color.GREEN);
Snackbar.SnackbarLayout sl = (Snackbar.SnackbarLayout) sk.getView();
TextView t=sl.findViewById(android.support.design.R.id.snackbar_text);
t.setVisibility(View.GONE);
logcat的
致命異常:主 工藝:com.example.ankit.testing,PID:29950 的java。 lang.NullPointerException:嘗試調用虛擬方法上一個空對象引用「INT android.text.Layout.getLineCount()」at android.support.design.internal.SnackbarContentLayout.onMeasure(SnackbarContentLayout.java:85) at android.view.View.measure(View.java:18820) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java: 5961) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.support.design.widget.Snackbar $ SnackbarLayout.onMeasure(Snackbar.java:335) at android.view.View.measure( View.java:18820) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5961) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) at android.view.View.measure(View.java:18820) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5961 ) 在android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391) 在android.view.View.measure(View.java:18820) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java :5961) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:18820) at android.view.ViewGroup.measureChildWithMargins( ViewGroup.java:5961) 在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465) 在android.widget.LinearLayout.measureVertical(LinearLayout.java:748) 在android.widget.LinearLayout.onMeasure(LinearLayout中。的java:630) 在android.view.View.measure(View.java:18820) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5961) 在android.widget.FrameLayout.onMeasure(FrameLayout.java: 194) 在com.android.internal.policy.PhoneWindow $ DecorView.onMeasure(PhoneWindow.java:2680) 在android.view.View.measure(View.java:18820) 在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2132) 在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1248) 在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1484) 在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139) 在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6091) 在android.view.Choreographer $ CallbackRecord。運行(Choreographer.java:858) at android.view.Choreographer.doCallbacks(Choreographer.java:670) at android.view.Choreographer.doFrame(Choreographer.java:606) at android.view.Choreographer $ FrameDisplayEventReceiver。運行(Choreographer.java:844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop( Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5437) at java.lang.reflect.Method.invoke(Native Method) at com.android.inte rnal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
https://stackoverflow.com/questions/32453946/how-to-customize-snackbars-layout/41154330 –