2014-10-05 3 views
1

Возможно ли иметь ActionBar название, состоящее из двух цветов, определенных только стилями XML? В это время я достигаю этого с SpannableString в Java-коде, но есть один недостаток. Когда приложение запускается, заголовок имеет какое-то время (до вызова onCreate()) по умолчанию.Название ActionBar с двумя цветами

enter image description here

Спасибо заранее.

ответ

0

Вы должны создать пользовательскую панель действий, используя метод ниже, я не делал все это как раз для создания настраиваемой панели действий с использованием вашего метода.

Создайте пользовательский экран действий с помощью этого метода. помните, что это не activity_main.xml create 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); 
} 

}

Смежные вопросы