列表视图不提供“设置”按钮

时间:2016-01-06 19:10:36

标签: java android android-layout

设置按钮在哪里(右角有3个小点)?以及如何归还? 当我开始使用ListView与另一个布局时,我的动作栏消失了。 可能是因为使用了另一种布局? enter image description here

MainActivity.java

 public class MainActivity extends ListActivity {

String[] values = new String[100];


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
//    setContentView(R.layout.activity_main);
   ListView listView = (ListView)findViewById(R.id.listView);
    for (int i=0;i<=99;i++){
        values[i]=Integer.toString(i+1);

    }
    MyCustomAdapter adapter = new MyCustomAdapter(this, values);
    setListAdapter(adapter);
    }


@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_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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        Intent intent = new Intent(MainActivity.this,SettingActivity.class);
        startActivity(intent);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    String item = (String) getListAdapter().getItem(position);
    Toast.makeText(this, item + " selected", Toast.LENGTH_SHORT).show();
}

}

1 个答案:

答案 0 :(得分:0)

使用默认ActionBar

确保您应用的主题(styles.xml中有一个Theme.AppCompat.*父级,其中还包含ActionBar。例如:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/specify_action_bar_color_here</item>
    <item name="colorPrimaryDark">@color/specify_status_bar_color_here</item>
    <item name="colorAccent">@color/specify_widget_color_here</item>
</style>

然后,确保您的Activity课程延伸AppCompatActivity,而不仅仅是Activity。例如:

public class MainActivity extends AppCompatActivity {
    //...
}