相关疑难解决方法(0)

更改searchview小部件的背景drawable

我正在尝试更改位于Android操作栏searchview小部件中的drawable.

目前它看起来像这样: 在此输入图像描述

但我需要将蓝色背景改为红色.

我尝试过很多东西,不用滚动我自己的搜索小部件,但似乎没有任何工作.

有人能指出我改变这个方向的正确方向吗?

android styles android-actionbar searchview background-drawable

122
推荐指数
5
解决办法
7万
查看次数

Android appcompat API 10折叠操作视图

我目前正在开发和需要支持Api10 +的Android应用程序我按照许多教程设置appcompat来管理创建操作栏.

链接如:https : //stackoverflow.com/a/21291156/2789106 http://developer.android.com/guide/topics/ui/actionbar.html

我不能做的只有三件事.

  1. 搜索打开时,搜索放大镜不会更改为我设置的可绘制对象.
  2. 我无法改变"后退"图标(主页上的按钮,左侧是徽标(这是一个不同于我在创建过程中传递的图像drawerToggle))
  3. 单击键盘搜索时,我无法以编程方式关闭(折叠)操作视图.(collapseActionView()在API 14中调用了调用)

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.drawable.ic_navigation_drawer,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() …
Run Code Online (Sandbox Code Playgroud)

android android-appcompat android-actionbar android-search

5
推荐指数
1
解决办法
3174
查看次数

如何去除Android SearchView 留下的空间?

我试图在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 的背景颜色

在此处输入图片说明

搜索不适合整个空间。为什么?

android android-appcompat searchview android-4.4-kitkat

5
推荐指数
1
解决办法
2288
查看次数

更改SearchView返回图标颜色

有没有办法在SearchView扩展时更改SearchView上显示的箭头的颜色? 在此输入图像描述

我已经尝试了一切没有结果.

android android-fragments

2
推荐指数
1
解决办法
5838
查看次数

如何更改SearchView后退按钮

我的工具栏上有一个SearchView,我想更改默认后退按钮的图标。

这是我的工具栏:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/my_awesome_toolbar"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/actionBarSize"
    app:titleTextColor="@android:color/black"
    android:elevation="5dp">

</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)

这是我的SearchView的布局:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item android:id="@+id/search"
        android:title="@string/search"
        app:icon="@drawable/ic_search_black_24dp"
        android:icon="@drawable/ic_search_black_24dp"
        app:showAsAction="always|collapseActionView"
        android:maxWidth="50dp"
        app:actionViewClass="android.support.v7.widget.SearchView"/>

</menu>
Run Code Online (Sandbox Code Playgroud)

这就是我在活动中创建选项菜单的方式:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search_team, menu);

    SearchManager searchManager = (SearchManager)
            getSystemService(Context.SEARCH_SERVICE);
    searchMenuItem = menu.findItem(R.id.search);

    searchView = (SearchView) searchMenuItem.getActionView();

    ImageView searchClose = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
    searchClose.setImageResource(R.drawable.ic_action_cancel_black);
    searchClose.setVisibility(View.VISIBLE);

    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) searchClose.getLayoutParams();
    params.gravity = Gravity.RIGHT;
    searchClose.setLayoutParams(params);

    searchClose.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //Clear query
            searchView.setQuery("", false); …
Run Code Online (Sandbox Code Playgroud)

android searchview android-toolbar

2
推荐指数
1
解决办法
2585
查看次数