Lea*_*des 5 android android-appcompat searchview android-4.4-kitkat
我试图在Android的搜索视图之前删除左边的空间,但没有成功。我尝试了在互联网上找到的所有答案,但都没有奏效。我正在为此活动使用 AppCompat 主题。我的目标是 KitKat api (19)。
编辑
活动布置
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/MainLayout"
android:background="#6ED19E">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/BackgroundLayout"
android:background="#6ED19E">
<ImageView
android:src="@drawable/bgpattern"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PatternImageView"
android:scaleType="centerCrop" />
<TextView
android:text="Já estamos em muitas cidades\nEstamos na sua?"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ManyCityLabel"
android:textColor="#ffffff"
android:textSize="25dp"
android:width="20dp"
android:gravity="center"
android:textStyle="normal" />
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/LocationsListView"
android:background="#ffffff"
android:visibility="invisible" />
Run Code Online (Sandbox Code Playgroud)
菜单
<?xml version="1.0" encoding="utf-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<item android:id="@+id/LocationSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:showAsAction="always"
tools:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>
Run Code Online (Sandbox Code Playgroud)
我以编程方式做的图标化的东西,因为当我更改 xml 时不起作用
编辑 如果我设置 SearchView 的背景颜色
搜索不适合整个空间。为什么?
您可以执行以下操作:
隐藏应用栏,onCreate()如下所示:
// Hide UI first
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
Run Code Online (Sandbox Code Playgroud)
在布局文件中将背景设置为绿色(或您的颜色),添加一个SearchView并将背景设置为SearchView白色,如下所示:
<android.support.constraint.ConstraintLayout
...
android:background="#00FF00"
...>
<android.support.v7.widget.SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF" />
...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
....
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我非常确定您的其他搜索界面代码应该可以工作。您只需重定向您的事件调用即可。
| 归档时间: |
|
| 查看次数: |
2288 次 |
| 最近记录: |