问题描述
作为标题说,我当扩展到listactivity有问题显示动作条。
as said in the title, I am having problem displaying the actionbar when extended to listactivity.
正如你可以看到下面,我已经试过requestwindowfeature,但它仍然没有出现。
As you can see below, I have tried requestwindowfeature but it is still not showing.
public class AlarmListActivity extends ListActivity {
private AlarmListAdapter mAdapter;
private AlarmDBHelper dbHelper = new AlarmDBHelper(this);
private Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.activity_alarm_list);
mContext = this;
mAdapter = new AlarmListAdapter(this, dbHelper.getAlarms());
setListAdapter(mAdapter);
//ActionBar actionBar = getSupportActionBar();
//actionBar.setLogo(R.drawable.ic_launcher);
//actionBar.setDisplayUseLogoEnabled(true);
//actionBar.setDisplayShowHomeEnabled(true);
}
styles.xml
styles.xml
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
清单
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".HomeScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="GOHOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SecondMainActivity"
android:label="@string/title_activity_second_main" >
<intent-filter>
<action android:name="GOHOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.kaixian.ticmeds.alarmclock.AlarmListActivity"
android:label="@string/app_name" >
</activity>
<activity android:name="com.example.kaixian.ticmeds.alarmclock.AlarmScreen" />
<activity android:name="com.example.kaixian.ticmeds.alarmclock.AlarmDetailsActivity" />
<service android:name="com.example.kaixian.ticmeds.alarmclock.AlarmService"
android:enabled="true"/>
<receiver android:name="com.example.kaixian.ticmeds.alarmclock.AlarmManagerHelper" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
Activity_alarm_list.xml
Activity_alarm_list.xml
<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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".AlarmListActivity" >
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
有没有办法延伸到ListActivity时,因为我需要它扩展到ListActivity显示动作条。请帮我。
Is there a way to show the ActionBar when extending to ListActivity cos I need it to extend to ListActivity. Please help me.
感谢你。
推荐答案
简单的方法是添加到您的清单,展现了动作条在默认情况下,你应该使用全息主题或它的后代之一:
Simplest way would be adding this to your manifest, to show the ActionBar by default you should use A Holo Theme or one of its descendants :
<activity
android:name="com.example.kaixian.ticmeds.alarmclock.AlarmListActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo" />
如果你的动作条有一个菜单,你可以在你的ListActivity这样的膨胀是:
If your ActionBar has a menu you can inflate it in your ListActivity like this :
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.your_menu, menu);
return super.onCreateOptionsMenu(menu);
}
我建议做一方面是因为如果你不添加主题,你的清单,并只能通过onCreateOptionsMenu()膨胀,则可能是正确显示您的Listactivity麻烦,因为它不采取了paddingTop照顾,所以你的动作条可能覆盖顶部你的清单项目。
I recommend doing both because if you dont add the theme to your Manifest and only inflate via onCreateOptionsMenu() , you might have trouble with displaying your Listactivity properly because it doesnt take care of the paddingTop and so your ActionBar might overlay the top item of your list.
这篇关于当扩展到listactivity动作条不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!