android操作栏中的添加按钮
我试图在HealthyApp旁边添加一个按钮,但没有成功 这是我的初始代码和图像android操作栏中的添加按钮,android,android-actionbar,Android,Android Actionbar,我试图在HealthyApp旁边添加一个按钮,但没有成功 这是我的初始代码和图像 final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); 我想在HealthyApp旁边添加一个删除按钮,但是HealthyApp标题不见了 final ActionBar actionBar = getSupportActionBar(); actio
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
我想在HealthyApp旁边添加一个删除按钮,但是HealthyApp标题不见了
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.header_button, null);
Button mTitleTextView = (Button) mCustomView.findViewById(R.id.title_text);
mTitleTextView.setText("Delete");
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
删除任务
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#d9d9d9"
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="wrap_content">
<Button
android:text="Delete"
android:layout_width="wrap_content"
android:background="#000"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="16dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ImageView
android:src="@mipmap/to_do"
android:layout_marginTop="50dp"
android:layout_width="130dp"
android:layout_height="210dp"
android:id="@+id/imageView"
android:gravity="center"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="No List Found"
android:textSize="15dp"
android:textColor="@color/btn_login"
android:gravity="center"
android:id="@+id/NoData"
android:layout_centerHorizontal="true"
android:layout_below="@+id/imageView"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list_todo"
android:layout_weight="1"
android:layout_alignParentLeft="true" />
</RelativeLayout>
</RelativeLayout>
在xml中添加工具栏。并在活动主题中使用NoActionBar
。
将这些工具栏添加到顶部的xml中
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#131313"
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="wrap_content"
android:background="#00aaaaaa"
android:layout_gravity="right"
android:layout_height="match_parent">
<Button
android:text="Delete"
android:layout_width="wrap_content"
android:background="#000"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="16dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
输出:-
或
我认为只有图标才有可能……
在menu.xml中使用此项
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/delete"
android:icon="@drawable/YourImage"
app:showAsAction="always"></item>
</menu>
注意:-在活动布局中使用android:icon=“@drawable/yourmagewithtextdelete”
将您的图像放在这里。
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:background="@color/YourColor"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:theme="@style/about_toolbar"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/YourText"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/YourText"
/>
</android.support.v7.widget.Toolbar>
在您的清单中,活动标记
<activity
android:name=".YourActivity"
android:label="@string/YourActivityString"
android:theme="@style/YourTheme" />
,它有示例工具栏。但我不想使用图标,只想使用android按钮,然后你必须使用自定义工具栏。。。。。在xml中包含工具栏。。。。并在您的活动主题中使用NoActionBar
…先生,我在我的delete_任务布局中添加了android.support.v7.widget.Toolbar
,但按钮添加在操作栏下方。将其添加到活动标签android:theme=“@style/theme.AppCompat.Light.NoActionBar”
中。
public class YourActivity extends ActionBarActivity {
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_acticity_layout);
// Set a Toolbar to replace the ActionBar.
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
// ... your other methods
}
<activity
android:name=".YourActivity"
android:label="@string/YourActivityString"
android:theme="@style/YourTheme" />
<style name="YourTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">...</item> <!-- declare your styles -->
</style>