我在线性布局中有 activity_main 和 2 个按钮。我希望 ActionBar 中的这种布局带有图标
I have activity_main with 2 button in Linear Layout. And i want this layout in ActionBar with icons
<LinearLayout
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/action_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="@+id/action_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ok" />
</LinearLayout>
我希望将此布局添加到 ActionBar 中。另外我想在按钮中添加图标。
I want this layout to be addded in ActionBar
扩充您的布局并将其作为自定义视图添加到操作栏
ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
View customView = LayoutInflater.from(this).inflate(R.layout.my_layout, null);
getSupportActionBar().setCustomView(customNav, lp); // or getActionBar()
Also I want to add icons in the button
Use
android:drawableLeft="@drawable/icon"
或
android:drawableRight="@drawable/icon"
在按钮上添加图标
<LinearLayout
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/action_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="@+id/action_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ok" />
</LinearLayout>
我希望将此布局添加到 ActionBar 中。另外我想在按钮中添加图标。
I want this layout to be addded in ActionBar
扩充您的布局并将其作为自定义视图添加到操作栏
ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
View customView = LayoutInflater.from(this).inflate(R.layout.my_layout, null);
getSupportActionBar().setCustomView(customNav, lp); // or getActionBar()
Also I want to add icons in the button Use
android:drawableLeft="@drawable/icon"
或
android:drawableRight="@drawable/icon"
在按钮上添加图标