Notice
Recent Posts
Recent Comments
올해는 머신러닝이다.
android change titlebar diynamic 본문
출처 : http://stackoverflow.com/questions/3438276/change-title-bar-text-in-android
you can Change the Title of each screen (i.e. Activity) by setting their Android:label
<activity android:name=".Hello_World"
android:label="This is the Hello World Application">
</activity>
=> Custom - Title - bar
But if you want to Customize title-bar in your way, i.e. Want to put Image icon and custom-text
, then following code is running for me:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LinearLayout>
titlebar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400px"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView android:id="@+id/ImageView01"
android:layout_width="57px"
android:layout_height="wrap_content"
android:background="@drawable/icon1">
</ImageView>
<TextView
android:id="@+id/myTitle"
android:text="This is my new title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="@color/titletextcolor"
/>
</LinearLayout>
TitleBar.java
public class TitleBar extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
if ( customTitleSupported ) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
}
final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
if ( myTitleText != null ) {
myTitleText.setText("NEW TITLE");
// user can also set color using "Color" and then "Color value constant"
// myTitleText.setBackgroundColor(Color.GREEN);
}
}
}
strings.xml
The strings.xml file is defined under the values
folder.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Set_Text_TitleBar!</string>
<string name="app_name">Set_Text_TitleBar</string>
<color name="titlebackgroundcolor">#3232CD</color>
<color name="titletextcolor">#FFFF00</color>
</resources>
'Android > Tip&Tech' 카테고리의 다른 글
stateListDrawable (0) | 2011.06.17 |
---|---|
Sqlite3 에서 Table 이 있는지 없는지 검색하기 (0) | 2011.06.16 |
Fixed header in a TableLayout (1) | 2011.06.14 |
WORKING WITH JSON,XML AN ANDROID (3) | 2011.06.10 |
android HTTP GET,POST Examples (0) | 2011.06.10 |