Make custom default name look on Android

How to use the default window title style for androids to make my own TextView ?

I thought a lot and made a TextView that has everything that the default title bar has, with the exception of the text shadow (and some padding / fields, etc., I think).

Here, basically, I tried:

MainUI.xml

 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); } 

title_bar.xml

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myTitle" android:layout_height="fill_parent" android:layout_width="fill_parent" android:textAppearance="@android:style/TextAppearance.WindowTitle" android:background="@android:drawable/title_bar" android:text="This is my new title" /> 

Edit:

I found some interesting articles in makemachine and anddev .

Although I don't like this, I copied some of the attributes from the style.xml implementation.

Is there a way to avoid copying attributes in this static way?

Below it is shown that almost perfectly, the difference is that the original β€œcut” the first 2-3 pixels of the title shadow, but my TextView does not.

 <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myTitle" android:layout_height="fill_parent" android:layout_width="fill_parent" android:gravity="center_vertical" android:shadowColor="#BB000000" android:shadowRadius="2.75" android:singleLine="true" android:textAppearance="@android:style/TextAppearance.WindowTitle" android:background="@android:drawable/title_bar" android:text="This is my new title" /> 

It is also important to override the default android: windowTitleBackgroundStyle with a transparent color, since the default includes some add-ons, etc. that you don’t want to wrap your own title bar.

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="CustomTheme" parent="android:Theme"> <item name="android:windowTitleBackgroundStyle">@android:color/transparent</item> </style> </resources> 

Remember to include the theme in AndroidManifest.xml

+6
android
source share
1 answer

try it, it worked for me:

put the rest of the code in place.

  super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.main_header); TextView home = (TextView) findViewById(R.id.home); if ( home != null ) { /* your code here */ home.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // the action that u want to perform Menu.this.finish(); Intent i= new Intent(Main.this,Destination.class); startActivity(i); } }); } 

create layout file main_header

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Main Menu" android:textStyle="bold" android:textSize="10pt" /> <TextView android:id="@+id/home" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView1" android:layout_alignBottom="@+id/textView1" android:layout_alignParentRight="true" android:textStyle="bold" android:text="Home" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout> </LinearLayout> 

here, when we execute the code, it will show a custom title bar that has two texts, and when we click on it, it will move on to the next class (to your target class). we can also change the color, font size, etc., as well as add buttons, etc. into a custom title bar.

0
source share

All Articles