2
我會用圖標和文本自定義應用程序的每個活動的標題欄。我嘗試了一些方法,但它們不起作用。有誰能夠幫助我?如何自定義標題欄與Android應用程序中的圖像?
這是我的代碼示例:
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.activity_main);
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
}
// user can also set color using 「Color」 and then 「Color value constant」
// myTitleText.setBackgroundColor(Color.GREEN);
}
}
在XML:
<?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" >
<TextView
android:id="@+id/myTitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="appuntiiiiiii" />
</LinearLayout>`
可能重複[自定義標題與圖像](http://stackoverflow.com/questions/2086989/custom-title-with-image) – nbrooks