1
是否有可能讓ActionBar
標題由僅由XML樣式定義的兩種顏色組成?在這個時候,我用Java代碼中的SpannableString
來實現這一點,但有一個缺點。當應用程序啓動時,標題有一段時間(直到onCreate()被調用)默認樣式。有兩種顏色的ActionBar標題
在此先感謝。
是否有可能讓ActionBar
標題由僅由XML樣式定義的兩種顏色組成?在這個時候,我用Java代碼中的SpannableString
來實現這一點,但有一個缺點。當應用程序啓動時,標題有一段時間(直到onCreate()被調用)默認樣式。有兩種顏色的ActionBar標題
在此先感謝。
你必須使用下面的方法創建自定義操作欄,我沒有做到這一切只是提示使用你的方法創建自定義操作欄。
使用此方法創建自定義操作欄視圖。記住這不是activity_main.xml創建custom_actionbar.xml並過去這一行。
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rrrrrrrr--"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tttttttt"
android:textAppearance="?android:attr/textAppearanceLarge" />
MainActivity類別是
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
TextView mTitleTextView1 = (TextView) mCustomView
.findViewById(R.id.textView1);
mTitleTextView1.setText("DCBA");
mTitleTextView1.setTextColor(Color.GREEN);
TextView mTitleTextView2 = (TextView) mCustomView
.findViewById(R.id.textView2);
mTitleTextView2.setText("ABCD-");
mTitleTextView2.setTextColor(Color.GRAY);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
}
}