2016-11-10 2 views
1

Хотите создать пользовательский ActionBar с именем приложения в центре его, но он по-прежнему совмещен с левым. Вот XML из custom_actionbar.xmlЦентр TextView в пользовательском ActionBar горизонтально

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:background="@color/transparent"> 

     <TextView 
      android:id="@+id/nav_bar_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:background="@color/transparent" 
      android:singleLine="true" 
      android:textColor="@color/sue_green" 
      android:text="@string/app_name" 
      android:textAppearance="?android:attr/textAppearanceLarge"> 
     </TextView> 

</RelativeLayout> 

Вот на создание деятельности:

public class DeviceOverviewActivity extends Activity { 

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

     setTheme(R.style.Theme_SUE); 
     setContentView(R.layout.activity_device_overview); 

     final ActionBar actionBar = getActionBar(); 
     actionBar.setDisplayShowTitleEnabled(false); 
     actionBar.setDisplayShowHomeEnabled(false); 
     actionBar.setDisplayUseLogoEnabled(false); 

     LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View v = inflator.inflate(R.layout.custom_actionbar, null); 

     actionBar.setDisplayShowCustomEnabled(true); 
     actionBar.setCustomView(v); 
    } 
... 
} 

Можете ли вы посоветовать, что я делаю неправильно? Благодаря

+0

Try с LinearLayout и удалить эта строка android: layout_centerInParent = "true" – cuoka

ответ

0

Изменение в TextView сек шириной до match_parent и применить android:gravity="center_horizontal"

0

использование андроида поддержка ToolBar для пользовательских ActionBar ..

использовать эту ссылку для Tool bar ссылки

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