是否有任何选项可以在工具栏右侧添加 TICK MARK?
Is any option to add TICK MARK on the right side of the toolbar?
默认情况下 android 可以使用
启用工具栏左侧的后退箭头
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
就像我需要工具栏右侧的TICK MARK,有什么方法可以默认在android中启用TICK MARK。
下载 "done" png 图标
将图标复制到您的项目可绘制文件夹。
然后在 res/menu 中创建一个名为 menu_example.xml
的文件
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:icon="@drawable/ic_done_white_24dp"
android:title="@string/action_done"
app:showAsAction="always" />
</menu>
然后将以下代码添加到您的Activity。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_example, menu);
return true;
}
要为 tick 设置一个 onClick 侦听器,您可以执行以下操作:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_example, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Toast toast = Toast.makeText(getApplicationContext(), "Hello toast!", Toast.LENGTH_SHORT);
toast.show();
return true;
}
默认情况下 android 可以使用
启用工具栏左侧的后退箭头 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
就像我需要工具栏右侧的TICK MARK,有什么方法可以默认在android中启用TICK MARK。
将图标复制到您的项目可绘制文件夹。
然后在 res/menu 中创建一个名为 menu_example.xml
的文件<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:icon="@drawable/ic_done_white_24dp"
android:title="@string/action_done"
app:showAsAction="always" />
</menu>
然后将以下代码添加到您的Activity。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_example, menu);
return true;
}
要为 tick 设置一个 onClick 侦听器,您可以执行以下操作:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_example, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Toast toast = Toast.makeText(getApplicationContext(), "Hello toast!", Toast.LENGTH_SHORT);
toast.show();
return true;
}