SearchView on support.v7.appcompat library issue: default 9-patch background not renders properly

ArnauOrriols picture ArnauOrriols · Aug 17, 2013 · Viewed 15.2k times · Source

I'm developing an app with ActionBar using support.v7.appcompat library. The action bar works, the SearchView is shown, the hint shows. The only problem is that the background of the SearchView is not scalling properly. Insead of the usual, it appears big and with the 9-patch black lines.

Using:

  • Developing from command line, using ant debug to compile.
  • On Linux Mageia 3, ant version: Apache Ant(TM) version 1.8.4 compiled on January 11 2013
  • Linking to library with project.properties line:

android.library.reference.1=../../../../../sdk/extras/android/support/v7/appcompat/

  • Using @style/Theme.AppCompat.Light
  • Tested in device with CM10-1, in device with stock 4.1, and emulator with API 8 (Android 2.2). Same result in all devices.

Screenshot:

enter image description here

Code:

DiccionariCatala.java (main activity):

import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.support.v4.view.MenuItemCompat;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;


public class DiccionariCatala extends ActionBarActivity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }   

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_actions, menu);
        SearchManager SManager =  (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        MenuItem searchMenuItem = menu.findItem(R.id.action_search);
        SearchView searchViewAction = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
        searchViewAction.setSearchableInfo(SManager.getSearchableInfo(getComponentName()));
        searchViewAction.setIconifiedByDefault(false);
        return super.onCreateOptionsMenu(menu);
    }   

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch (item.getItemId()) {
                case R.id.action_search:
                    //openSearch();
                    return true;
                default:
                    return super.onOptionsItemSelected(item);
        }   
    }      
}

menu_actions.xml (menu xml)

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:diccionaricatala="http://schemas.android.com/apk/res-auto" >
    <item android:id="@+id/action_search"
          android:title="@string/action_search_title"
          diccionaricatala:showAsAction="ifRoom"
          diccionaricatala:actionViewClass="android.support.v7.widget.SearchView" />
</menu>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mypackage.apps"
      android:versionCode="1"
      android:versionName="1.0">
      <uses-sdk android:minSdkVersion="8"  android:targetSdkVersion="16"/>
      <application android:label="@string/app_name"
                   android:icon="@drawable/ic_launcher"
                   android:theme="@style/Theme.AppCompat.Light">

       <activity android:name="DiccionariCatala"
                 android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>
            <meta-data android:name="android.app.searchable"
                       android:resource="@xml/searchable"/>
        </activity>
   </application>
</manifest>

project.properties

target=android-16
android.library.reference.1=../../../../../sdk/extras/android/support/v7/appcompat/

Any help would me much apreciated. I can't find anything wrong, and there's also the weird fact that despide this, everything else work. Thanks.

Answer

ArnauOrriols picture ArnauOrriols · Aug 17, 2013

Ok, I want to kill myself. I've fixed it. Don't know how. I can't reproduce the bug again!

what I think has fixed the bug: I've added import android.support.v7.app.ActionBar;

Then I've removed it to reproduce the bug, but it's not back.

I also did uninstall Build-tools 18.0.1 (which is in italics and made me suspicious), so I thought it might be the source of the bug. But I've reinstalled it, and can't reproduce the bug either.

I don't know what else could possibly be. Anyway, moving on... (sight)

Edit:

It happened again, and this time I've been able to narrow it down. Turns out it is a bug of Build Tools v18.*, downgrading to v17 solves the issue.