为什么我的操作栏没有显示,我该如何解决?
Why is my actionbar not showing and how do I fix it?
好的,我正在使用 Android Studio 开发一个 Android 应用程序,但我在显示操作栏时遇到了真正的问题。从代码中,我看不出为什么不显示操作栏。任何人都可以找出可能导致它的原因吗?
主要Activity
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>
使用 ActionBarActivity
扩展您的 Activity
public class HomeActivity extends ActionBarActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
1- 在您的清单文件中进行更改,
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
2- 下载,android-support-v7-appcompat
3- 将下载的库添加到您的项目中
并扩展 Activity 而不是 ActionBarActivity。
希望对您有所帮助。
只是扩展了 ActionBarActivity 而不是 Activity
好的,我正在使用 Android Studio 开发一个 Android 应用程序,但我在显示操作栏时遇到了真正的问题。从代码中,我看不出为什么不显示操作栏。任何人都可以找出可能导致它的原因吗?
主要Activity
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>
使用 ActionBarActivity
扩展您的 Activitypublic class HomeActivity extends ActionBarActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
1- 在您的清单文件中进行更改,
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
2- 下载,android-support-v7-appcompat
3- 将下载的库添加到您的项目中
并扩展 Activity 而不是 ActionBarActivity。
希望对您有所帮助。
只是扩展了 ActionBarActivity 而不是 Activity