我正在开发android UX设计。我正在使用RelativeLayout
。我想在android中执行以下屏幕。
我是Android的新手,我不知道如何做到这一点。需要一些帮助。
答案 0 :(得分:2)
这是一个ActionBar(工具栏)菜单图标:
您需要在res / menu中添加一个菜单文件,例如:main.xml以这种方式形成:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_main"
android:title="@string/action_main"
android:orderInCategory="100"
android:icon="@drawable/ic_launcher"
app:showAsAction="ifRoom" />
</menu>
Over&#34; android:icon&#34;去你想要的那个,&#34; android:title&#34;用户长按图标时想要的那个。
编辑使用评论检查更新的代码
要让侦听器(onClick操作)通过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.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if(id == R.id.action_main){
Toast.makeText(getApplicationContext(), "Main action is selected!", Toast.LENGTH_SHORT).show();
// Toast only have a small duration to show something,
// even when you long press the item, the Title is also a
// Toast. You can literally do anything here. Show stuffs,
// hide it, open activities, close the app, etc
return true;
}
return super.onOptionsItemSelected(item);
}
答案 1 :(得分:1)
add in menul
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/phone"
android:title="@string/phone"
android:icon="@drawable/phone"
android:showAsAction="always"
/>
</menu
After that in java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case R.id.phone:
Toast.makeText(getBaseContext(), "You selected Phone", Toast.LENGTH_SHORT).show();
break;
}
return true;