我想在我的Android应用程序中创建一个菜单,但我不想通过按菜单按钮显示那个菜单,我只是想让它在没有它的情况下出现。
示例: 这是Android上的Google地图应用 我想在没有菜单按钮的情况下运行app时在底部显示这样的菜单。 我希望有人能得到我想要的东西:)
非常感谢。
答案 0 :(得分:1)
如果您只需要菜单,请执行以下操作:
public class Test extends ListActivity {
String classes[] = { "first item", "second item", "third item", "fourth item"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setListAdapter(new ArrayAdapter<String>(Test.this,
android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String planet = classes[position];
try {
Class ourClass = Class.forName("com.test.test." + planet);
Intent ourIntent = new Intent(Test.this, ourClass);
startActivity(ourIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
此代码不会像上图那样创建菜单,但它会为您提供标准菜单,您可以根据需要自定义它。
希望这有用。
答案 1 :(得分:0)
您可以使用RelativeLayout执行此操作。 例如:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
答案 2 :(得分:0)
你正在看的是一个放在ActionBar上的Spinner。
Android的网站上有一个关于微调器的教程,您可以在http://developer.android.com/resources/tutorials/views/hello-spinner.html
找到它