2015-10-12 2 views
0

Я хочу создать пользовательский интерфейс, который выглядит как панель действий, хотя и не ведет себя как одна. Мне нужна помощь только в пользовательском интерфейсе. Я имею в виду, что я не хочу явно указывать размер текста, стиль или другой атрибут. Я добавляю изображение, чтобы сделать его более понятным.Создание собственного собственного пользовательского бара

enter image description here

Я уже создал пользовательский интерфейс. Ниже приведен код.

<?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:background="@color/action_bar_grey" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/custom_tabs_grey" 
     android:orientation="horizontal" > 

     <TextView 
      style="@style/Text.Bold" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@color/custom_tabs_grey" 
      android:gravity="center_horizontal" 
      android:paddingBottom="@dimen/padding_extra_wide" 
      android:paddingTop="@dimen/padding_extra_wide" 
      android:text="@string/waiting_to_upload" 
      android:textColor="@android:color/black" /> 

     <View 
      android:layout_width="@dimen/status_button_border_width" 
      android:layout_height="match_parent" 
      android:layout_marginTop="@dimen/medium_narrow" 
      android:layout_marginBottom="@dimen/medium_narrow" 
      android:background="@android:color/darker_gray" /> 

     <TextView 
      style="@style/Text.Bold" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@color/custom_tabs_grey" 
      android:gravity="center_horizontal" 
      android:padding="@dimen/padding_extra_wide" 
      android:text="@string/uploaded" 
      android:textColor="@android:color/black" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="@dimen/medium_narrow" 
     android:layout_marginBottom="@dimen/medium_narrow" 
     android:orientation="horizontal" > 

     <FrameLayout 
      android:id="@+id/upload_waiting" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginRight="@dimen/medium_narrow" 
      android:layout_weight="1" > 
     </FrameLayout> 

     <FrameLayout 
      android:id="@+id/upload_done" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="@dimen/medium_narrow" 
      android:layout_weight="1" > 
     </FrameLayout> 
    </LinearLayout> 

</LinearLayout> 

здесь я явно давая атрибут текста, добавив, вид на делитель и т.д. Мой вопрос является ли я должен сделать все, что в явном виде. Разве это не андроид. Как я сделал для разделителя. Но все же фон и текст не точны, как в обычных вкладках.

<LinearLayout 
    android:divider="?android:attr/actionBarDivider" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
    android:showDividers="middle" > 

     <TextView 
      style="?android:attr/buttonBarStyle" 
      ....MORE CODE 

Есть ли предложение или фрагмент кода, чтобы помочь?

ответ

1

Использовать Toolbar.

<android.support.v7.widget.Toolbar 
    android:id="@+id/my_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize"> 

    <TextView 
     android:id="@+id/my_toolbar_title" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:gravity="center" /> 

</android.support.v7.widget.Toolbar> 

Вы можете использовать Toolbar, как и любой другой точки зрения. Отрегулируйте его размер, добавьте текст и т. Д.

public class MainActivty extends AppCompatActivity { 
    private Toolbar toolbar; 
    private TextView toolbarTitle; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     toolbar = (Toolbar) findViewById(R.id.my_toolbar); 
     toolbarTitle = (TextView) findViewById(R.id.my_toolbar_title); 

     setSupportActionBar(toolbar); 
     toolbarTitle.setText("Waiting To Upload"); 
    } 
} 
Смежные вопросы