Título personalizado con imagen


Estoy creando un título personalizado para la actividad deshabilitando standard one y administrando todo yo mismo. Me pregunto si es posible reemplazar/tema standart título a mis necesidades.

Puedo personalizar el tamaño, la imagen de fondo y el texto a través de temas cambiando los elementos windowXYZStyle.

Lo único que no pude encontrar - cómo puedo agregar imagen en lugar de texto. He intentado requestWindowFeature(Window.FEATURE_CUSTOM_TITLE) y asignar diseño personalizado - pero no parece funcionar.

EDITAR: Aquí hay un informe de sugerencias de pruebas, el código está por debajo - resultado-la vista de imagen no se muestra.

Actividad

public class SettingsActivity extends PreferenceActivity  {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);

    }
}

XML :

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/title"
    android:layout_width="fill_parent"
    android:layout_height="26dip"
    android:paddingLeft="5dip"
    android:background="@drawable/titlebar_bg"
    android:layout_gravity="left|center"
>
    <ImageView
        android:id="@+id/logo"
        android:src="@drawable/title_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
Author: Alex Volovoy, 2010-01-18

4 answers

Es posible establecer su propio diseño de título personalizado, sin embargo, el orden de ejecución importa. Debes hacer las cosas en este orden:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_title);

Además, es posible que necesite aumentar el tamaño del título; si no lo hace, entonces la parte inferior de su diseño personalizado puede estar cubierta por su Actividad. Puede cambiar el tamaño agregando un tema que especifique el tamaño del título. Esto iría en un archivo XML de valores:

<resources>
    <style name="LargeTitleTheme">
        <item name="android:windowTitleSize">40dip</item>
    </style>
</resources>

Entonces usted tendría que establecer el tema para su Actividad (o Aplicación, si desea que toda la aplicación tenga esta barra de título personalizada) en AndroidManifest.xml:

<activity android:name=".MyCustomTitleActivity" android:theme="@style/LargeTitleTheme" />
 35
Author: Daniel Lew,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-01-18 16:22:07

Siempre puedes usar:

requestWindowFeature(Window.FEATURE_NO_TITLE);

Y luego crea tu propia barra de título dentro de la vista de tu Actividad.

 6
Author: Dave Webb,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-01-18 15:31:24

¿Está seguro de que necesita usar una imagen en el título en lugar de simplemente combinarla como parte de su imagen de fondo y dejar el título en blanco? Usando una imagen NinePatch Esperaría que usted sería capaz de lograr un resultado que se vería bien en independientemente del dispositivo?

 1
Author: Casebash,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-04-29 01:15:06

He utilizado el siguiente código para ajustar mi título personalizado a la pantalla

<ImageView
    android:id="@+id/header_img"
    android:src="@drawable/header_img"
    android:layout_width="700dip"
    android:layout_height="70dip" />
 1
Author: arunprakashpj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-14 18:41:15