好的,所以我正在使用Android Studio开发一个Android应用程序,我在操作栏显示时遇到了麻烦。从代码中,我看不出动作栏没有显示的原因。有人能发现可能导致它的原因吗?
主要活动
public class HomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
主要活动xml
<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".HomeActivity"
>
<ListView
android:id="@+id/apps_list"
android:layout_width="match_parent"
android:layout_height="420dp"
android:divider="@color/divider"
android:layout_alignParentBottom="true"
>
</ListView>
我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.easylauncher" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".HomeActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
样式xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/primary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:icon">@color/icons</item>
<item name="android:divider">@color/divider</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight & colorSwitchThumbNormal. -->
</style>
</resources>
答案 0 :(得分:1)
使用ActionBarActivity扩展您的活动
public class HomeActivity extends ActionBarActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
答案 1 :(得分:0)
1-在您的清单文件中进行更改,
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
2-下载,android-support-v7-appcompat
3-将下载的库添加到项目中
并扩展Activity而不是ActionBarActivity。
希望它会有所帮助。答案 2 :(得分:0)
只是扩展 ActionBarActivity 而非活动