Android appcompat API 10 vista de acción de contracción
Actualmente estoy desarrollando y la aplicación de Android que necesita para apoyar Api10 + He seguido muchos tutoriales para establecer appcompat para gestionar la creación de la barra de acción.
Enlaces como: https://stackoverflow.com/a/21291156/2789106 http://developer.android.com/guide/topics/ui/actionbar.html
- Widget.AppCompat.Button colorButtonNormal muestra gris
- Android 5.0: cómo cambiar el color de título de las aplicaciones recientes?
- Crash en Android 2.3.3 después de actualizar a la biblioteca de soporte 25.0.0 (java.lang.NoSuchMethodError: android.view.View.isAttachedToWindow)
- Diferentes estilos de colorControlActivated en Android
- Error: no se pudo encontrar el destino con la cadena de hash 'android-21'
Sólo hay tres cosas que no puedo hacer.
- Cuando se abre la búsqueda, la lupa de búsqueda NO cambia a la que se puede dibujar.
- No puedo cambiar el icono de "atrás" (el botón de inicio de la página, dejado al logotipo (es una imagen diferente de la que pasé en la creación de la página de
drawerToggle
) - No puedo cerrar (contraer) de forma programática la vista de acción cuando se hace clic en la búsqueda de teclado. (Llamando a
collapseActionView()
se implementó en API 14)
Aquí está mi código:
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() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); // Restore app state if any if (savedInstanceState == null) { mLeftMenuContainer = (LinearLayout) findViewById(R.id.left_menu_container); mLeftMenuContainer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { // return TRUE to avoid tap on back view return true; } }); mDrawerLayout.closeDrawer(mLeftMenuContainer); } // enable ActionBar app icon to behave as action to toggle nav drawer getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setLogo(R.drawable.ic_action_bar_logo); } /* Called whenever we call supportInvalidateOptionsMenu() */ @Override public boolean onPrepareOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content // view if (mDrawerLayout != null && mLeftMenuContainer != null) { boolean drawerOpen = mDrawerLayout.isDrawerOpen(mLeftMenuContainer); for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(!drawerOpen); } } return super.onPrepareOptionsMenu(menu); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @Override public boolean onCreateOptionsMenu(Menu menu) { mMenu = menu; // Inflate the menu; this adds items to the action bar if it is present. // enable ActionBar app icon to behave as action to toggle nav drawer getMenuInflater().inflate(R.menu.main, menu); MenuItem searchItem = menu.findItem(R.id.action_bar_search); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchableInfo info = searchManager.getSearchableInfo(getComponentName()); searchView.setSearchableInfo(info); AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); searchText.setHintTextColor(getResources().getColor(R.color.color_action_bar_search_text)); searchText.setTextColor(getResources().getColor(R.color.color_action_bar_search_text)); searchView.setIconifiedByDefault(true); // Getting the 'search_plate' LinearLayout. View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate); // Setting background of 'search_plate' to personal defined drawable. if (searchPlate != null) { searchPlate .setBackgroundResource(R.drawable.texfield_search_view_theme); } // Set search view clear icon ImageView searchIconClearView = (ImageView) searchView .findViewById(android.support.v7.appcompat.R.id.search_close_btn); if (searchIconClearView != null) { Log.v(LOG_TAG, "Should Change Clear Icon here"); searchIconClearView .setImageResource(R.drawable.ic_action_bar_clear_search); } // Set search view Magnifier icon ImageView searchIcon = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon); if (searchIcon != null) { Log.v(LOG_TAG, "Should Change Search Icon here"); searchIcon.setImageResource(R.drawable.ic_action_bar_back); } // Set on click to open a fragment, not a activity final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { // Do something return true; } @Override public boolean onQueryTextSubmit(String query) { Log.v(LOG_TAG, "Performed search with: " + query); searchView.clearFocus(); return true; } }; searchView.setOnQueryTextListener(queryTextListener); MenuItemCompat.setOnActionExpandListener(searchItem, new OnActionExpandListener() { @Override public boolean onMenuItemActionCollapse(MenuItem arg0) { mMenu.findItem(R.id.action_bar_cart).setVisible(true); return true; } @Override public boolean onMenuItemActionExpand(MenuItem arg0) { getSupportActionBar().setIcon(R.drawable.ic_action_bar_logo); mMenu.findItem(R.id.action_bar_cart).setVisible(false); return true; } }); return super.onCreateOptionsMenu(menu); }
¿Puede alguien por favor decirme si estoy haciendo algo mal?
– EDITAR –
Me las arreglé para arreglar la pregunta número 1 y 2:
Lo que hay que hacer es definir homeUpIcon en su Tema. Así que si usted está apoyando API 10 como yo:
<style name="Theme.MyTheme" parent="@style/Theme.AppCompat.Light"> <item name="searchViewSearchIcon">@drawable/your_search_icon</item> <!-- API 13- Support --> <item name="homeAsUpIndicator">@drawable/your_back_icon</item> <!-- API 14+ --> <item name="android:homeAsUpIndicator">@drawable/your_back_icon</item> </style>
encontrado en
ActionBarSherlock: cambiar homeAsUpIndicator no funciona
Y Cambiar el fondo dibujable del widget de búsqueda
La pregunta más importante aún está pendiente y si alguien sabe la respuesta, publica aquí!
- Cómo utilizar y estilo nuevo AlertDialog de appCompat 22.1 y superior
- GetActionBar () devuelve Null (AppCompat-v7 21)
- Cómo crear AppCompatDialog de AlertDialog.Builder o equivalente?
- Botones planos sin material Lollipop
- Android spinner con subrayado appcompat
- Cómo obtener AppCompatDelegate modo actual si predeterminado es auto
- Android: TextView no respeta el androide: TextViewStyle usando appcompat-v7 22.1.1
- java.lang.IllegalStateException: Necesita usar un tema Theme.AppCompat (o descendente) con esta actividad
Prueba esto:
public boolean onQueryTextSubmit(String query) { MenuItemCompat.collapseActionView(searchItem); return false; }
- Puntero nulo en la vista inflada al cargar por segunda vez un fragmento de mapa de google
- Selector de lugar Cierre automático después del lanzamiento