我正在尝试从searchView中删除下界线,但是findViewById方法始终会返回null
@Override
protected void onResume() {
super.onResume();
View view = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
view.setBackgroundColor(Color.TRANSPARENT);
}
答案 0 :(得分:0)
在onCreate
@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_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" />