我会使用图标和文本自定义应用程序的每个活动的标题栏。我尝试了一些方法,但它们不起作用。有人可以帮助我吗?
这是我的代码示例:
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>`
答案 0 :(得分:1)
我知道这可能对你的需求有点过分但如果你真的想要一些很酷的东西你应该尝试实施ActionBar。它可以在API11中使用,但你可以实现ActionBarSherlock看起来和工作方式几乎相同。我喜欢它!
至于你的代码,没有ImageView,所以你怎么可能显示图像。在TextView
之前需要一个imageView