我的工具栏后面这个奇怪的白色矩形是什么?
What's this strange white rectangle behind my toolbar?
我整天都在尝试摆脱它,但无济于事。尝试为它周围的每个视图和布局提供不可见的背景颜色。还尝试减小其所在布局和视图的大小。那些尖锐的白色边缘仍然存在。这些是什么?另外,您好,这是文本填充器,网站上说代码太多,文本太少。 “嗨文本填充器,你好吗?”
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="@+id/mainToolbar"
layout="@layout/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mainToolbar">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/tab_anim_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#00FFFFFF">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/searchToolbar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:background="#A106A1"
android:elevation="2dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlways">
<!-- dummy to catch focus -->
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:layoutDirection="rtl"
app:iconifiedByDefault="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"/>
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_scrolling"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
代码中的工具栏:
//code to make the toolbar edges round
MaterialToolbar searchToolbar = findViewById(R.id.searchToolbar);
MaterialShapeDrawable searchbarBackground = (MaterialShapeDrawable) searchToolbar.getBackground();
searchbarBackground.setShapeAppearanceModel(
searchbarBackground.getShapeAppearanceModel()
.toBuilder()
.setBottomRightCorner(CornerFamily.ROUNDED,100)
.setBottomLeftCorner(CornerFamily.ROUNDED,100)
.build()
);
//code to add search function
SearchView searchView = findViewById(R.id.searchView);
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);//so that button on keyboard is a check
searchView.setQueryHint("Search...");
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
ItemAdapter.getFilter().filter(newText);
return false;
}
});
是AppBarLayout
的影子。使用:
<com.google.android.material.appbar.AppBarLayout
app:elevation="0dp"
android:background="@android:color/transparent"
我整天都在尝试摆脱它,但无济于事。尝试为它周围的每个视图和布局提供不可见的背景颜色。还尝试减小其所在布局和视图的大小。那些尖锐的白色边缘仍然存在。这些是什么?另外,您好,这是文本填充器,网站上说代码太多,文本太少。 “嗨文本填充器,你好吗?”
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <include android:id="@+id/mainToolbar" layout="@layout/toolbar" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/mainToolbar"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/tab_anim_appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center|top" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:background="#00FFFFFF"> <com.google.android.material.appbar.MaterialToolbar android:id="@+id/searchToolbar" style="@style/Widget.MaterialComponents.Toolbar.Primary" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center|top" android:background="#A106A1" android:elevation="2dp" app:contentInsetLeft="0dp" app:contentInsetStart="0dp" app:layout_scrollFlags="scroll|enterAlways"> <!-- dummy to catch focus --> <LinearLayout android:layout_width="0px" android:layout_height="0px" android:focusable="true" android:focusableInTouchMode="true" /> <androidx.appcompat.widget.SearchView android:id="@+id/searchView" android:layout_width="match_parent" android:layout_height="wrap_content" android:animateLayoutChanges="true" android:layoutDirection="rtl" app:iconifiedByDefault="true" android:layout_marginLeft="30dp" android:layout_marginRight="30dp"/> </com.google.android.material.appbar.MaterialToolbar> </com.google.android.material.appbar.AppBarLayout> <include layout="@layout/content_scrolling"/> </androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.constraintlayout.widget.ConstraintLayout>
代码中的工具栏:
//code to make the toolbar edges round MaterialToolbar searchToolbar = findViewById(R.id.searchToolbar); MaterialShapeDrawable searchbarBackground = (MaterialShapeDrawable) searchToolbar.getBackground(); searchbarBackground.setShapeAppearanceModel( searchbarBackground.getShapeAppearanceModel() .toBuilder() .setBottomRightCorner(CornerFamily.ROUNDED,100) .setBottomLeftCorner(CornerFamily.ROUNDED,100) .build() ); //code to add search function SearchView searchView = findViewById(R.id.searchView); searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);//so that button on keyboard is a check searchView.setQueryHint("Search..."); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { ItemAdapter.getFilter().filter(newText); return false; } });
是AppBarLayout
的影子。使用:
<com.google.android.material.appbar.AppBarLayout
app:elevation="0dp"
android:background="@android:color/transparent"