I want to use a light theme, but still have an actionbar visible.
From here it looks like this should work:
<activity android:theme="@style/Theme.AppCompat.Light" ... >
But when I add any android:theme the actionbar disappears.
I'm probably missing something obvious...
Edit: in case it helps
From the build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.company.app"
minSdkVersion 15
targetSdkVersion 21
versionCode 5
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/screen_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".owg">
<TextView android:id="@+id/textHeader"
android:textSize="24sp"
android:textColor="#006699"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:visibility="visible"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Empty set"
android:visibility="invisible"
/>
</LinearLayout>
main.java
package com.company.app;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.content.Intent;
import android.view.View;
public class Main extends ListActivity {
private String[] mBooks = new String[]{ "Informational", "Extensions" };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MySimpleArrayAdapter booksAdapter = new MySimpleArrayAdapter(this,mBooks);
ListView lv = (ListView) findViewById(android.R.id.list);
lv.setAdapter(booksAdapter);
}
}
use this:
<activity android:theme="@style/Theme.AppCompat.Light.DarkActionBar" ... >
instead of :
<activity android:theme="@style/Theme.AppCompat.Light" ... >
It should work. The issue here, that you use style without actionBar now, and there is some choices how action bar will look(see related styles)
//Use this to fill your action bar with items
@Override public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.your_menu_name, menu);
return true;
}
or if yout want custom view for your actionBar
//Getting action bar
mActionBar = getActionBar();
and then use
mActionBar.setCustomView(mCustomView);//View object for your actionBar
mActionBar.setDisplayShowCustomEnabled(true)
EDIT: if you can't see title bar you can create it programmatically
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.settings);
activity.setTitle("Settings");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.