我会使用图标和文本自定义应用程序的每个活动的标题栏。我尝试了一些方法,但它们不起作用。有谁能够帮我?
这是我的代码示例:
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>`