I'm trying to change the color of the ActionBar in my app. The color was changed in the preview tap when opening the layout file, but not when I run it on my device (5.0.1). I need the status bar to be also colored.
Here is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="Test" parent="android:Theme.Material.Light">
<item name="android:actionBarStyle">#style/TestActionBar</item>
</style>
<style name="TestActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#color/primary_dark</item>
<item name="android:statusBarColor">#color/primary_dark</item>
<!--<item name="android:colorPrimary">#color/primary_dark</item>-->
<!--<item name="android:actionMenuTextColor">#FFFFFF</item>-->
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/primary_darker</item>
</style>
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowBackground">#color/primary</item>
<item name="colorControlNormal">#color/iron</item>
<item name="colorControlActivated">#color/white</item>
<item name="colorControlHighlight">#color/white</item>
<item name="android:textColorHint">#color/iron</item>
<item name="colorButtonNormal">#color/primary_darker</item>
<item name="android:colorButtonNormal">#color/primary_darker</item>
</style>
<style name="AppTheme.Dark.Dialog" parent="Theme.AppCompat.Dialog">
<item name="colorAccent">#color/white</item>
<item name="android:textColorPrimary">#color/iron</item>
<item name="android:background">#color/primary</item>
</style>
</resources>
My manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.motassem.beacontest" >
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Material.Light.DarkActionBar" >
<activity
android:name=".TestActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".LoginActivity"
android:theme="#style/AppTheme.Dark" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SignupActivity"
android:theme="#style/AppTheme.Dark" >
</activity>
<activity
android:name=".HomeActivity"
android:label="#string/title_activity_home" >
</activity>
</application>
</manifest>
My layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.example.motassem.beacontest.HomeActivityFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".HomeActivity">
<fragment android:name="com.example.motassem.beacontest.HomeActivityFragment"
android:id="#+id/frag_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#layout/fragment_home" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#android:color/black" />
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal" />
</LinearLayout>
And my fragment.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/string_total_saved"
android:id="#+id/tvTotal"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:textSize="40sp"
android:id="#+id/textView2"
android:layout_below="#+id/tvTotal"
android:layout_centerHorizontal="true" />
Edit
After adding AppTheme in the solution's style.xml, the action bar is missing.
In your Activity (which has to extend an AppCompatActivity) or in your Application you should use a AppCompat Theme.
If you are not using a Toolbar in your layout use somenthing like:
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
</style>
Otherwise, if you are using a Toolbar use:
<style name="AppTheme.NoActionBar" >
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
I added the following to style.xml and applied it for my activity
<style name="Accelerator" parent="#style/Theme.AppCompat">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/primary_dark</item>
<item name="colorControlHighlight">#color/primary_darker</item>
<item name="colorControlActivated">#color/white</item>
<item name="android:navigationBarColor">#color/primary</item>
<item name="android:statusBarColor">#color/primary_dark</item>
<item name="android:textColorPrimary">#color/accent</item>
</style>
Related
I want to add a background to a button, as I have already done several times. I have a drawable resource file with the appropriate background. However, if I link this, it will not be accepted, instead only one color will be used as the background.
I had the suspicion that it could be a mistake in my Styles.xml but nothing is called too colored in these. What can be the reasons why Android Studio does not recognize a background or where could I have defined a general theme of how buttons should look? I can't remember having put on something like that. I tried something similar with an EditText, I had no problems here, so I think it is a specific button problem.
Also if I change the background color to a plain whit it is not changing anything and still showing a dark blue.
Update: If I change the preview style (upper middel of the preview) to DialogStyle the button background works. How can that be if there is nothing defined in der styles?
Update: I added a new version of my button this time initializing the background in a extra style. Result is that it is still not showing the right color. I also tried it with black but nothing happend.
Thanks for any help.
Button
<Button
android:id="#+id/buttonRegistrieren"
android:layout_width="232dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"
android:background="#drawable/btnbackground"
android:onClick="WriteData"
android:text="#string/Registrieren"
android:textAllCaps="false"
android:textColor="#color/colorWhite"
android:textSize="16dp"></Button>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">#android:color/black</item>
</style>
<style
name="SplashTheme"
parent="AppTheme">
<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ButtonStyle" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:textColor">#color/colorWhite</item>
<item name="android:background">#color/colorBlack</item>
</style>
<style
name="SecondTheme"
parent="AppTheme">
<item name="android:windowFullscreen">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="DialogStyle" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
</resources>
btnbackground.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="#FF5256AC"
android:endColor="#FF662D91"
android:startColor="#FF29ABE2"
android:type="linear" />
<corners android:radius="150dp">
</corners>
</shape>
Button with Theme
<Button
android:id="#+id/buttonLogin"
android:layout_width="160dp"
android:layout_height="45dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Anmelden"
android:textAllCaps="true"
android:textColor="#color/colorWhite"
android:textSize="16sp"
android:theme="#style/ButtonStyle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="426dp"
/>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="edmt.dev.androideatitv2client">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:theme">
<activity android:name=".PasswordActivity"></activity>
<activity android:name=".LoginActivity" />
<activity android:name=".RegistrationActivity" />
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UpdatePasswordActivity" />
<activity android:name=".UpdateProfileActivity" />
<activity android:name=".ProfileActivity" />
<activity
android:name=".HomeActivity"
android:label="#string/title_activity_home"
android:theme="#style/AppTheme.NoActionBar" />
<service android:name=".services.MyFCMServices">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
You have to add Width and Height to your Shapein
btnbackground.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="#FF5256AC"
android:endColor="#FF662D91"
android:startColor="#FF29ABE2"
android:type="linear" />
<corners android:radius="150dp">
</corners>
If you don't use AndroidX, you have to change your Theme from Theme.MaterialComponents.Light.NoActionBar to Theme.AppCompat.Light.NoActionBar
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">#android:color/black</item>
</style>
<style
name="SplashTheme"
parent="AppTheme">
<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ButtonStyle" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:textColor">#fff</item>
<item name="android:background">#000</item>
</style>
<style
name="SecondTheme"
parent="AppTheme">
<item name="android:windowFullscreen">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="DialogStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
Button
<Button
android:id="#+id/buttonLogin"
android:layout_width="160dp"
android:layout_height="45dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Anmelden"
android:textAllCaps="true"
android:textColor="#fff"
android:textSize="16sp"
android:theme="#style/ButtonStyle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
here's the result :
I solved the same problem changing the theme from Theme.MaterialComponents.Light.NoActionBar to Theme.AppCompat.Light.NoActionBar. Hope it helps and happy coding!
Have you tried changing the view from Button to ImageButton?
I am using Android Studio 3.2 and Android API 23 develop the app, when I try to set a custom title bar it display the error You cannot combine custom titles with other title features.
I google the the error and try some answers on so, but it can't solve the problem, I am stucked.
the code is as following,
the manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shashiwang.shashiapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
the styles:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<!--<item name="windowActionBar">false</item>-->
</style>
<style name="TitleBarLayout" >
<item name="android:background">#color/colorTitleBarBg</item>
<item name="android:layout_height">#dimen/title_bar_height</item>
<item name="android:layout_width">match_parent</item>
</style>
<style name="TitleBarTitle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:color">#color/colorTitleBarTitle</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:text">#string/app_name</item>
<item name="android:textSize">#dimen/title_bar_title_font_size</item>
<item name="android:textStyle">bold</item>
</style>
<style name="TitleBarContactLayout">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:gravity">center</item>
<item name="android:layout_marginRight">10dp</item>
</style>
<style name="TitleBarContactIcon">
<item name="android:layout_width">#dimen/title_bar_contact_icon_width</item>
<item name="android:layout_height">#dimen/title_bar_contact_icon_height</item>
<item name="android:src">#drawable/ic_contact</item>
</style>
<style name="TitleBarContactText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:text">#string/title_bar_contact_text</item>
<item name="android:textSize">#dimen/title_bar_contact_font_size</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/titleBarContainer"
style="#style/TitleBarLayout">
<TextView
android:id="#+id/TitleBarTitle"
style="#style/TitleBarTitle" />
<LinearLayout
android:id="#+id/TitleBarContactContainer"
style="#style/TitleBarContactLayout">
<ImageView
android:id="#+id/titleBarContactIcon"
style="#style/TitleBarContactIcon" />
<TextView
android:id="#+id/TitleBarContactText"
style="#style/TitleBarContactText" />
</LinearLayout>
</RelativeLayout>
the activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar_layout);
}
I'm trying to edit the Title text size because it changes when in landscape screen. I found changing the dimension in SP can solve the problem. So I did this...
added a style in style.xml
<style name="Toolbar.TitleText"
parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">30sp</item>
</style>
and then in app_bar_main.xml under android.support.v7.widget.Toolbar i added this line
app:titleTextAppearance="#style/Toolbar.TitleText"
Now it gives the desired result on Main activity but all others activities are same. I have around 10 activities in my app. How can I change all the activities' Title? Please help. Thanks in advance.
my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/title_main"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".splash"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ch_1"
android:label="#string/ch_1" />
<activity
android:name=".ch_2"
android:label="#string/ch_2" />
<activity
android:name=".ch_3"
android:label="#string/ch_3" />
<activity
android:name=".ch_4"
android:label="#string/ch_4" />
<activity
android:name=".ch_5"
android:label="#string/ch_5" />
<activity
android:name=".ch_6"
android:label="#string/ch_6" />
<activity
android:name=".ch_7"
android:label="#string/ch_7" />
<activity
android:name=".ch_8"
android:label="#string/ch_8" />
<activity
android:name=".ch_9"
android:label="#string/ch_9" />
<activity
android:name=".ch_10"
android:label="#string/ch_10" />
<activity
android:name=".ch_11"
android:label="#string/ch_11" />
<activity android:name=".ch_12"
android:label="#string/ch_12" />
<activity
android:name=".ch_13"
android:label="#string/ch_13" />
<activity
android:name=".ch_14"
android:label="#string/ch_14" />
<activity
android:name=".ch_15"
android:label="#string/ch_15" />
<activity android:name=".view" />
</application>
my style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#color/white</item>
<item name="colorButtonNormal">#color/colorPrimary</item>
<item name="android:textAppearanceButton">#style/TextAppearance.AppCompat.Button.Custom</item>
</style>
<style name="Toolbar.TitleText"
parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">24sp</item>
</style>
<style name="TextAppearance.AppCompat.Button.Custom">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">28sp</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ActionButtonStyle" parent="#android:style/Widget.Holo.ActionButton">
<item name="android:minWidth">0dip</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingRight">0dip</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
</style>
You can use <include> tag to achieve it.
Just like this
<LinearLayout 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:orientation="vertical"
tools:context="com.dzq.aprivate.view.activity.MainActivity">
<include layout="#layout/lay_actionbar"/>
<FrameLayout
android:id="#+id/lay_container"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<include layout="#layout/lay_main_bottom"/>
</LinearLayout>
Use <include layout="#layout/toolbar_header"/> in every Activity you want.
Ok, I have resolved the issue. The previous code was not working for other layouts because activity_main.xml was using toolbar instead of action bar, so i had to write another piece of style for the action bar.
I added these style..
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">24sp</item>
</style>
and then added the item in AppTheme like this..
<item name="actionBarStyle">#style/MyActionBar</item>
and it's working fine now. Thanks everyone for replying.
IDE: Android Studio 1.1.0
ENV: Debugging on usb-connected phone using Android API v10.
I'm trying to use AppCompat to support Android API v8 and up. Compiles fine but crashes when the activity is drawn, saying:
lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
...however, in AndroidManifest.xml I have:
<application
android:name=".objects.PikCMS"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/ThemeOverlay.AppCompat"
>
Thank you & please forgive my frustration. I've been reading A LOT of related but unhelpful info. }8,(
Other Info
I do not want to force a specific theme.
I would like to avoid using different files for different API versions. However, I don't mind adding different versions of same property next to each other.
I had errors in styles.xml for items introduced in v11 (like "buttonBarStyle" & "showDividers"). After reading about the issue, I had thought AppCompat would "fill in the blanks" for pre11 APIs but (in my configuration) it isn't. These are currently all commented out -- until I find out how to use them with AppCompat. Similarly, I had problems with the layout files -- these problematic properties were deleted.
Activity class: Login.java extends :ActionBarActivity:. I'm also importing "android.support.v7.app.ActionBarActivity" but I'm not sure if I need all of it as I do not implicitly use the action bar (but I might in the future).
Code Files
build.gradle (Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.kjackson324.pikcms"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
}
dependencies {
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
compile fileTree(include: ['*.jar'], dir: 'libs')
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kjackson324.pikcms" >
<application
android:name=".objects.PikCMS"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/ThemeOverlay.AppCompat"
>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
<activity
android:name=".Login"
android:configChanges="keyboardHidden|orientation"
android:label="#string/title_activity_login"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="com.kjackson324.pikcms.Login" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Navigation"
android:configChanges="keyboardHidden|orientation"
android:label="#string/title_activity_navigation"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="com.kjackson324.pikcms.Navigation" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".PickHistory"
android:configChanges="keyboardHidden|orientation"
android:label="#string/title_activity_pik_log"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="com.kjackson324.pikcms.PickHistory" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!--
...bla, bla, bla...
(much more of the same, no new attributes used)
-->
<activity
android:name=".ConfigLocFields"
android:label="#string/title_activity_config_loc_fields"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.kjackson324.pikcms.Navigation" />
<intent-filter>
<action android:name="com.kjackson324.pikcms.ConfigLocFields" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="simple_center" parent="">
<!--item name="android:layout_gravity">center</item-->
<!--item name="android:gravity">center</item-->
<item name="android:dialogLayout">?android:layout_gravity</item>
</style>
<style name="lblLoggedIn" parent="#android:style/TextAppearance.Small">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:text">#string/sys_logged_in</item>
<item name="android:layout_gravity">top|right</item>
<item name="android:gravity">top|center_vertical</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:paddingLeft">4dp</item>
<item name="android:paddingRight">4dp</item>
</style>
<style name="tvLoggedIn" parent="#android:style/TextAppearance.Small">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:inputType">none</item>
<item name="android:gravity">top</item>
<item name="android:layout_gravity">top|left</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:layout_weight">2</item>
</style>
<style name="layout_master">
<item name="android:orientation">vertical</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!--item name="showDividers">end</item-->
<item name="android:layout_alignParentTop">true</item>
<item name="android:layout_centerHorizontal">true</item>
</style>
<style name="layout_loggedin">
<!--item name="buttonBarStyle">?android:attr/buttonBarStyle</item-->
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">?android:attr/dividerVertical</item>
<item name="android:gravity">bottom|center</item>
</style>
<style name="layout_bodyscroll">
<item name="android:layout_width">fill_parent</item>
<item name="android:fillViewport">true</item>
<item name="android:layout_height">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_marginTop">#dimen/activity_bodyscroll_margin</item>
<item name="android:layout_marginBottom">#dimen/activity_bodyscroll_margin</item>
<item name="android:layout_marginLeft">#dimen/activity_bodyscroll_margin</item>
<item name="android:layout_marginRight">#dimen/activity_bodyscroll_margin</item>
</style>
<style name="layout_bodylinear">
<item name="android:orientation">vertical</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="layout_btnbar_frame">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
</style>
<style name="layout_btnbar_linear" parent="">
<!--item name="buttonBarStyle">?android:attr/buttonBarStyle</item-->
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">?android:attr/dividerVertical</item>
<item name="android:gravity">bottom|center</item>
<item name="android:layout_gravity">bottom</item>
</style>
<style name="layout_btnbar_btn" parent="">
<!--item name="buttonBarStyle">?android:attr/buttonBarStyle</item-->
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:textColor">#android:color/primary_text_dark</item>
<item name="android:paddingTop">#dimen/activity_vertical_margin</item>
<item name="android:paddingBottom">#dimen/activity_vertical_margin</item>
</style>
<style name="menu_btn" parent="layout_btnbar_btn">
<item name="android:textAppearance">#android:style/TextAppearance.Large</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
<style name="hidden">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">0dp</item>
<item name="android:editable">false</item>
<item name="android:autoText">false</item>
<item name="android:visibility">invisible</item>
<item name="android:inputType">none</item>
</style>
<style name="field_edittext">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">7dp</item>
<item name="android:layout_marginTop">3dp</item>
<item name="android:layout_marginLeft">2dp</item>
<item name="android:layout_marginRight">2dp</item>
<item name="android:layout_column">1</item>
<item name="android:layout_weight">2</item>
<item name="android:textColor">#android:color/primary_text_dark</item>
<item name="android:autoText">true</item>
<item name="android:gravity">bottom</item>
</style>
<style name="tvFieldLabel">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:layout_gravity">top</item>
<item name="android:gravity">top</item>
</style>
<style name="field_edittext_note" parent="field_edittext">
<item name="android:layout_height">125dp</item>
<item name="android:gravity">top</item>
</style>
<style name="tvTableField">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_gravity">bottom|right</item>
<item name="android:layout_weight">0</item>
<item name="android:layout_column">0</item>
<item name="android:textAppearance">#android:style/TextAppearance.Medium</item>
<item name="android:textColor">#android:color/secondary_text_dark</item>
<item name="android:gravity">center_vertical</item>
<item name="android:inputType">none</item>
</style>
<style name="spinTails">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!--item name="android:background">?android:attr/dividerVertical</item-->
<item name="android:padding">8dp</item>
</style>
<style name="tvFieldColPrimary" parent="tvTableField">
<item name="android:textColor">#android:color/primary_text_dark</item>
<item name="android:paddingRight">8dp</item>
</style>
<style name="tvFieldColSecondary" parent="tvFieldColPrimary">
<item name="android:textColor">#android:color/secondary_text_dark</item>
</style>
</resources>
./layout/activity_login.xml (my first activity)
<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"
tools:context="com.kjackson324.pikcms.Login"
android:id="#+id/layLogin" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/tvId"
android:visibility="invisible"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="#+id/scrollView4"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout13"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/entry_employee"
android:id="#+id/tvName"
/>
<Spinner
android:id="#+id/spinEmployees"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/lbl_password"
android:id="#+id/tvPassword"
android:layout_marginTop="#dimen/activity_vertical_margin"/>
<EditText
android:id="#+id/txtPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:ems="10"
android:text="admin"/>
</LinearLayout>
</ScrollView>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linearLayout14"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom|center"
android:weightSum="2"
android:layout_gravity="bottom">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_begin"
android:id="#+id/btnLogin"
android:background="#android:color/transparent"
android:layout_weight="1"
android:textColor="#android:color/primary_text_dark"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:onClick="onClick"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_clear"
android:id="#+id/button7"
android:background="#android:color/transparent"
android:layout_weight="1"
android:textColor="#android:color/primary_text_dark"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</RelativeLayout>
Devices | logcat
03-03 11:14:37.386 1891-1891/com.kjackson324.pikcms D/AndroidRuntime﹕ Shutting down VM
03-03 11:14:37.386 1891-1891/com.kjackson324.pikcms W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40018560)
03-03 11:14:37.413 1891-1891/com.kjackson324.pikcms E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kjackson324.pikcms/com.kjackson324.pikcms.Login}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
at android.app.ActivityThread.access$1500(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.kjackson324.pikcms.Login.onCreate(Login.java:38)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
at android.app.ActivityThread.access$1500(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
You need to replace your theme in the application tag of your manifest:
<application android:theme="#style/Theme.AppCompat">
ThemeOverlay should only be used with an actionBar with the new actionBarTheme attribute or with a toolbar. More informations here: https://chris.banes.me/2014/11/12/theme-vs-style/
In my Project i have add Library ActionBar Sherlock and create the custom theme for my project.
I have created custom theme from here.
But after applying the theme my Progress Dialog in not aligned(means not displayed in the center of screen).
Please not this issue appears in API Level 11 or above.
Here i have attached the screen shot of emulator running OS 4.2.2.
I am unable to figure out this issue...
ScreenShot ::
MyCustomTheme ::(values folder)
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Custom_ThemeSherlockLight" parent="#style/Theme.Sherlock.Light">
<item name="actionBarItemBackground">#drawable/selectable_background_exampthemesherlocklightle</item>
<item name="popupMenuStyle">#style/PopupMenu.Custom_ThemeSherlockLight</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Custom_ThemeSherlockLight</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Custom_ThemeSherlockLight</item>
<item name="actionDropDownStyle">#style/DropDownNav.Custom_ThemeSherlockLight</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Custom_ThemeSherlockLight</item>
<item name="actionModeBackground">#drawable/cab_background_top_exampthemesherlocklightle</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_exampthemesherlocklightle</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Custom_ThemeSherlockLight</item>
</style>
<style name="ActionBar.Solid.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_exampthemesherlocklightle</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_exampthemesherlocklightle</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_exampthemesherlocklightle</item>
<item name="progressBarStyle">#style/ProgressBar.Custom_ThemeSherlockLight</item>
</style>
<style name="ActionBar.Transparent.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ActionBar">
<item name="background">#drawable/ab_transparent_exampthemesherlocklightle</item>
<item name="progressBarStyle">#style/ProgressBar.Custom_ThemeSherlockLight</item>
</style>
<style name="PopupMenu.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_exampthemesherlocklightle</item>
</style>
<style name="DropDownListView.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_exampthemesherlocklightle</item>
</style>
<style name="ActionBarTabStyle.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_exampthemesherlocklightle</item>
</style>
<style name="DropDownNav.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_exampthemesherlocklightle</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_exampthemesherlocklightle</item>
<item name="android:dropDownSelector">#drawable/selectable_background_exampthemesherlocklightle</item>
</style>
<style name="ProgressBar.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_exampthemesherlocklightle</item>
</style>
<style name="ActionButton.CloseMode.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_exampthemesherlocklightle</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Custom_ThemeSherlockLight.Widget" parent="#style/Theme.Sherlock">
<item name="popupMenuStyle">#style/PopupMenu.Custom_ThemeSherlockLight</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Custom_ThemeSherlockLight</item>
</style>
<style name="Theme.Sherlock.Translucent" parent="#style/Theme.Sherlock">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
<style name="Theme.Translucent" parent="#android:style/Theme.Translucent">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
</resources>
AndroidManifest.xml ::
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Custom_ThemeSherlockLight" >
<activity
android:name="com.example.testproject.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ProgressDialog pDialog=new ProgressDialog(this);
pDialog =ProgressDialog.show(this,null, "Please Wait..", true);
pDialog.setContentView(R.layout.progress);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
progress.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="130dp"
android:layout_height="80dp"
android:background="#android:color/transparent"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:gravity="center"
android:text="Please wait.."
android:textColor="#color/black" />
</LinearLayout>
Please change the following lines of code in
progress.xml file
android:layout_width="130dp"
android:layout_height="80dp"
to
android:layout_width="match_parent"
android:layout_height="match_parent"
It should display in the center of the screen now.
Hope this helps!
Edit: Please change the layout_width attribute of TextView to "wrap_content".
I don't know if it helps or not. But to fix the cropping issue of "Please wait" text. Change the layout_width to "wrap_content" like this
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:gravity="center"
android:text="Please wait.."
android:textColor="#color/black" />