Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialps17
8,408 PointsHow do I make my app's name visible on Android 2.2?
I'm on the Adding a Different Icon for Older Menus video and following the instructions exactly. When he loads his app on an Android 2.2 emulator, you can see the app name at the top. However, when mine loads up, the app name and the title bar doesn't show. Help?
ps17
8,408 PointsHere's my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.blogreader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainListActivity"
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=".BlogWebViewActivity"
android:label="@string/title_activity_blog_web_view" >
</activity>
</application>
</manifest>
And here's my main activity:
package com.example.blogreader;
// Imports here
public class MainListActivity extends ListActivity {
public static final int NUMBER_OF_POSTS = 20;
public static final String TAG = MainListActivity.class.getSimpleName();
protected JSONObject mBlogData;
protected ProgressBar mProgressBar;
private final String KEY_TITLE = "title";
private final String KEY_AUTHOR = "author";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_list);
mProgressBar = (ProgressBar) findViewById(R.id.progressBar1);
if (isNetworkAvailable()) {
mProgressBar.setVisibility(View.VISIBLE);
GetBlogPostsTask getBlogPostsTask = new GetBlogPostsTask();
getBlogPostsTask.execute();
}
}
// There's a lot more code...
I don't know what that title bar is referred to as in Android 2.2, but I would like to know how to get that (And maybe an ActionBar too). All of my code is based on the video I linked above. You can see the title bar in the video around the 4:34 mark
1 Answer
Luke O'Neill
7,822 PointsAdd this code to an xml file in the "values" folder. Name it whatever you want.
<!-- Sets the text styles -->
<?xml version="1.0" encoding="utf-8"?>
<!-- Sets the text styles -->
<resources>
<style name="CustomWindowTitleText" parent="android:TextAppearance.WindowTitle">
<item name="android:textSize">20dip</item>
<item name="android:textColor">#5599FF</item>
<item name="android:textStyle">bold|italic</item>
</style>
<!-- Changes the background color of the title bar -->
<style name="CustomWindowTitleBackground">
<item name="android:background">#222222</item>
</style>
<!-- Set the theme for the window title -->
<!-- NOTE: setting android:textAppearence to style defined above -->
<style name="CustomWindowTitle" parent="android:WindowTitle">
<item name="android:textAppearance">@style/CustomWindowTitleText</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">0</item>
<item name="android:shadowRadius">5</item>
<item name="android:shadowColor">#1155CC</item>
</style>
<!-- Override properties in the default theme -->
<!-- NOTE: you must explicitly the windowTitleSize property, the title bar will not re-size automatically, text will be clipped -->
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">40dip</item>
<item name="android:windowTitleStyle">@style/CustomWindowTitle</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
Then add this to reference the new file. ```xml <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/CustomTheme">
ps17
8,408 PointsThanks!
Luke O'Neill
7,822 PointsLuke O'Neill
7,822 PointsCould you put a snap shot of your code in, por favor?