600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > android actionbar 自定义布局 ActionBar 自定义布局定义

android actionbar 自定义布局 ActionBar 自定义布局定义

时间:2020-04-27 00:02:48

相关推荐

android actionbar 自定义布局 ActionBar 自定义布局定义

在Activity中加载ActionBar的自定义布局

(1)ActionBar加载自定义布局的代码封装如下:

private void setActionBarLayout(int layoutId) {

// TODO Auto-generated method stub

ActionBar actionBar = getActionBar();

if(null != actionBar){

actionBar.setDisplayShowHomeEnabled(false);

actionBar.setDisplayShowCustomEnabled(true);

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View v = inflater.inflate(layoutId, null);

ActionBar.LayoutParams lParams = new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

actionBar.setCustomView(v, lParams);

}

}

(2)在onCreate()方法中调用该方法,并传入自定义的布局文件ID:

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setActionBarLayout(R.layout.actionbar_layout);

}

(3)自定义布局文件“actionbar_port_layout.xml”代码如下:

xmlns:android="/apk/res/android"

android:layout_width="match_parent"

android:layout_height="44dp"

android:orientation="horizontal"

android:gravity="center_vertical"

android:background="#008000">

android:layout_marginLeft="24dp"

android:layout_width="36dp"

android:layout_height="36dp"

android:src="@drawable/ic_launcher"/>

android:layout_marginLeft="24dp"

android:layout_weight="1"

android:layout_width="0dp"

android:layout_height="36dp"

android:hint="Please input "

android:id="@+id/et_input"/>

android:layout_marginRight="20dp"

android:layout_marginLeft="20dp"

android:layout_width="30dp"

android:layout_height="30dp"

android:src="@drawable/action_search"/>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。