2

When I create any application, Android always gives me the same title bar. What do I need to do to customize it (background and text)? Maybe change style.xml or change the onCreate() method?

I updated AndroidManifest.xml and styles.xml:

@AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.searchmedicinelayout"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.app.searchmedicinelayout.SearchMedicineActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".DetailMedicine"
            android:label="@string/detail"
            android:parentActivityName="com.app.searchmedicinelayout.SearchMedicineActivity" >

        </activity>
    </application>

</manifest>

@styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
    </style>

</resources>
Matthew Read
  • 1,365
  • 1
  • 30
  • 50
user2353978
  • 43
  • 2
  • 8

2 Answers2

1

you can change the title of application and the activitys in the AndroidManifest.xml file. You change the values of fields "android:label" with the your custom text. The "@string/app_name" is a label declared in the file "strings" (folder "values" of your projetc). There, you can create or modify new labels.

  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    android:name="shooterfugio.aquiniela2.MiApp">
    <activity
        android:name="shooterfugio.aquiniela2.MiTareaAsincrona"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.facebook.LoginActivity"
              android:theme="@android:style/Theme.Translucent.NoTitleBar"
              android:label="@string/app_name" />
    <activity android:name=".Main"
              android:label="@string/app_name" />
    <activity android:name=".Aquiniela"
              android:label="@string/app_name" />
    <activity android:name=".IntroduceTexto"
              android:label="@string/app_name" />
    <activity
        android:name=".Popup1"
        android:label="@string/info"
        android:theme="@android:style/Theme.Dialog" >
    </activity>  
    <meta-data android:name="com.facebook.sdk.ApplicationId" 
               android:value="@string/applicationId" />
</application>

To change the background, you must do it in the file name_activity.xml, as follows:

  <LinearLayout android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_gravity="center_horizontal"
              android:gravity="center_horizontal"
              android:background="@drawable/image_background"
              android:id="@+id/main_ui_container">

Note: "image_background" is the name of a file with a background image (located in the folder "drawable")

  • I think you don't understand my question. I want to change title bar which contain the icon, lable, project name... I only change background and modify text size, text color, text align of it. I don't want show it to the layout. – user2353978 Jun 02 '13 at 18:47
0

I would probably need to look at your code, but the title bar's title and style are generally defined in the AndroidManifest.xml. More specifically, you want to look at the part that defines your application:

<application
 android:icon="@drawable/icon" 
 android:label="@string/app_name"
 android:theme="@style/customTheme">

Now, to change the title bar's text, you have to go to your strings.xml and edit the value for app_name. If, on the other hand, you want to restyle it, you need to create a style file under res/values/, with some styling xml. For example, the following code:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <style name="customTheme" parent="android:Theme.Light">
    <item name="android:windowBackground">#1BE032</item>
    <item name="android:colorBackground">#1BE032</item>
    </style>
    </resources>

will make the window look a bit too green-ish.

In any case, it would be helpful to post your AndroidManifest and any custom themes, if you are using any.

verybadalloc
  • 5,768
  • 2
  • 33
  • 49
  • I just want to change background on the title bar and set text center and change size. The AndroidManifest is default when I create project. I have updated 2 file on top. – user2353978 Jun 02 '13 at 18:39