Android findViewById从searchView返回null
我试图从searchView中删除Underline,但findViewById方法始终返回nullAndroid findViewById从searchView返回null,android,android-recyclerview,Android,Android Recyclerview,我试图从searchView中删除Underline,但findViewById方法始终返回null @Override protected void onResume() { super.onResume(); View view = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_plate); view.setBackgroundColor(Color.TRANSPARENT); }
@Override
protected void onResume() {
super.onResume();
View view = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
view.setBackgroundColor(Color.TRANSPARENT);
}
在
onCreate中初始化SearchView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
searchView = findViewById(R.id.search);
View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
v.setBackgroundColor(Color.TRANSPARENT);
}
布局R.layout.activity\u main
<android.support.v7.widget.SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
在您的onCreate中初始化SearchView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
searchView = findViewById(R.id.search);
View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
v.setBackgroundColor(Color.TRANSPARENT);
}
布局R.layout.activity\u main
<android.support.v7.widget.SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
你能分享你的xml文件吗?你能分享你的xml文件吗?我想知道为什么现在,我改进了android.widget.SearchView,但试图将它用作android.support.v7.widget.SearchView,但无论如何我想知道为什么现在,我改进了android.widget.SearchView,但试图将它用作android.support.v7.widget.SearchView,但无论如何