解决方案 »

  1.   

    自定义ActionBar视图,
    getSupportActionBar().setCustomView(LayoutInflater.from(this).inflate(R.layout.title, null)); 
    其中title为自定义的布局文件。
      

  2.   

    然后再设置
    getSupportActionBar().setDisplayShowCustomEnabled(true);
         getSupportActionBar().setDisplayShowHomeEnabled(false);
         getSupportActionBar().setDisplayShowTitleEnabled(false);
    这几个属性
      

  3.   

    请问这个布局文件是在drawable文件夹下定义吗
    还有我的只能ActionBar actionBar = this.getActionBar();  不能getSupportActionBar() 对功能有没有什么影响
      

  4.   

    请问这个布局文件是在drawable文件夹下定义吗
    还有我的只能ActionBar actionBar = this.getActionBar();  不能getSupportActionBar() 对功能有没有什么影响
    第一个问题,我写的是R.layout.title,当然是定义在layout下;
    第二个问题,getSupportActionBar()是因为我使用一个开源库,用来兼容低版本的手机,你使用getActionBar()是没有问题的,就是3.0以下版本是不兼容的。
      

  5.   

    请问这个布局文件是在drawable文件夹下定义吗
    还有我的只能ActionBar actionBar = this.getActionBar();  不能getSupportActionBar() 对功能有没有什么影响
    第一个问题,我写的是R.layout.title,当然是定义在layout下;
    第二个问题,getSupportActionBar()是因为我使用一个开源库,用来兼容低版本的手机,你使用getActionBar()是没有问题的,就是3.0以下版本是不兼容的。
    谢谢
    我的布局文件这样写的,但不知道为什么还是不能居中显示
    <?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="match_parent" >    <TextView
            android:id="@+id/about_actionbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="关于"
            android:textSize="18sp" /></RelativeLayout>
      

  6.   

    请问这个布局文件是在drawable文件夹下定义吗
    还有我的只能ActionBar actionBar = this.getActionBar();  不能getSupportActionBar() 对功能有没有什么影响
    第一个问题,我写的是R.layout.title,当然是定义在layout下;
    第二个问题,getSupportActionBar()是因为我使用一个开源库,用来兼容低版本的手机,你使用getActionBar()是没有问题的,就是3.0以下版本是不兼容的。
    Activity中的代码
                    super.onCreate(savedInstanceState);

    ActionBar actionBar = this.getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setIcon(R.drawable.icon_back_btn_normal);

    setContentView(R.layout.about);
    /**
     * actionBar添加自定义view
     */
    View actionbarLayout = LayoutInflater.from(this).inflate(R.layout.about_actionbar, null);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(actionbarLayout);
      

  7.   

    请问这个布局文件是在drawable文件夹下定义吗
    还有我的只能ActionBar actionBar = this.getActionBar();  不能getSupportActionBar() 对功能有没有什么影响
    第一个问题,我写的是R.layout.title,当然是定义在layout下;
    第二个问题,getSupportActionBar()是因为我使用一个开源库,用来兼容低版本的手机,你使用getActionBar()是没有问题的,就是3.0以下版本是不兼容的。
    谢谢
    我的布局文件这样写的,但不知道为什么还是不能居中显示
    <?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="match_parent" >    <TextView
            android:id="@+id/about_actionbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="关于"
            android:textSize="18sp" /></RelativeLayout>
    android:gravity="center"加上这句
      

  8.   

    请问这个布局文件是在drawable文件夹下定义吗
    还有我的只能ActionBar actionBar = this.getActionBar();  不能getSupportActionBar() 对功能有没有什么影响
    第一个问题,我写的是R.layout.title,当然是定义在layout下;
    第二个问题,getSupportActionBar()是因为我使用一个开源库,用来兼容低版本的手机,你使用getActionBar()是没有问题的,就是3.0以下版本是不兼容的。
    谢谢
    我的布局文件这样写的,但不知道为什么还是不能居中显示
    <?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="match_parent" >    <TextView
            android:id="@+id/about_actionbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="关于"
            android:textSize="18sp" /></RelativeLayout>
    android:gravity="center"加上这句在RelativeLayout里加了android:layout_gravity="center"
    在TextView里加了android:gravity="center"都没用 
      

  9.   

    <?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:orientation="horizontal" 
        android:gravity="center_vertical"
        android:background="@color/maincolor">    <ImageButton
            android:id="@+id/arClose"
            android:layout_width="50dp"
            android:layout_height="44dp"
            android:src="@drawable/icon_back" 
            android:onClick="onClick"
            android:background="@null" />    <TextView
            android:id="@+id/arTitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="@color/white"
            android:text="Title"
            android:gravity="center"
    android:textSize="16sp"
             />
    </LinearLayout>