gpt4 book ai didi

android - 如何为每个 Activity 的操作栏 Sherlock 创建自定义样式

转载 作者:行者123 更新时间:2023-11-30 03:23:59 25 4
gpt4 key购买 nike

我在我的项目中使用 actionbarsherlock

并且我想根据我当前所处的 Activity 设置不同的操作栏样式

如何为每个 Activity 定义自定义操作栏样式?

最佳答案

在 oncreate 中试试这个,它会起作用

    setContentView(R.layout.mobile_change);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setCustomView(R.layout.header);
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("#5B5292")));
TextView txt = (TextView) findViewById(R.id.tv_title_header);
Typeface font = Typeface.createFromAsset(getAssets(), "georgia.ttf");
txt.setText("CHANGE MOBILE NO.");
txt.setTextSize(13);
txt.setTypeface(font);

如果您需要标题布局,请尝试使用此代码,否则您可以根据需要创建任何标题

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:gravity="center" >
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="center" >

<TextView
android:id="@+id/tv_title_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:singleLine="true"
android:text=""
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:gravity="center"
android:padding="2dp" >

<ImageView
android:id="@+id/iv_merchant_logo_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxHeight="50dp" />
</LinearLayout>
</LinearLayout>

关于android - 如何为每个 Activity 的操作栏 Sherlock 创建自定义样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18573566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com