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" />
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 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>
Im using JakeWharton-Android-ViewPagerIndicator in my application and i also created custom window title.
whem im trying ti run the app, i see that the custom title is half blocked by the rest of the activity.
http://postimg.org/image/c5w27rzj7/
this is part the main activity code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.layout_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
FragmentPagerAdapter adapter = new TubeFmAdapter(getSupportFragmentManager());
ViewPager pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adapter);
TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
indicator.setViewPager(pager);
initEvents();
}
android manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TubeFM"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/WindowTitleTheme">
<activity
android:name="com.TubeFM.activities.MainActivity"
android:label="TubeFM"
android:screenOrientation="portrait"
android:theme="#style/Theme.PageIndicatorDefaults">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
android:exported="true"/>
</intent-filter>
<meta-data android:name="isLaunchableActivity" android:value="true"/>
</activity>
<activity
android:name="com.TubeFM.activities.VideoPlayerActivity"
android:label="#string/app_name"
android:exported="true"
android:screenOrientation="portrait">
</activity>
<meta-data android:name="isLaunchableActivity" android:value="false"/>
</application>
</manifest>
custom window title layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:paddingRight="5dip"
>
<ImageView
android:id="#+id/ic_search"
android:src="#drawable/ic_action_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip">
<AutoCompleteTextView
android:id="#+id/editTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:background="#drawable/text_search_background"
android:hint="#string/search_artist"
android:imeOptions="actionSearch"
android:inputType="text"
android:visibility="invisible"
android:drawableRight="#drawable/ic_action_search">
</AutoCompleteTextView>
</LinearLayout>
</LinearLayout>
activity theme:
<resources>
<style name="Theme.PageIndicatorDefaults" parent="android:Theme">
<item name="vpiIconPageIndicatorStyle">#style/Widget.IconPageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
</style>
<style name="Widget">
</style>
<style name="Widget.TabPageIndicator" parent="Widget">
<item name="android:gravity">center</item>
<item name="android:background">#drawable/vpi__tab_indicator</item>
<item name="android:paddingLeft">22dip</item>
<item name="android:paddingRight">22dip</item>
<item name="android:paddingTop">12dp</item>
<item name="android:paddingBottom">12dp</item>
<item name="android:textAppearance">#style/TextAppearance.TabPageIndicator
</item>
<item name="android:textSize">11sp</item>
<item name="android:maxLines">1</item>
</style>
<style name="TextAppearance.TabPageIndicator" parent="Widget">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/vpi__dark_theme</item>
</style>
<style name="Widget.IconPageIndicator" parent="Widget">
<item name="android:layout_marginLeft">6dp</item>
<item name="android:layout_marginRight">6dp</item>
</style>
</resources>
ok , so who face the same problem.
the solution is to make that activity use theme parent android:theme to all the relevant styles.
e.g :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RidesTheme" parent="android:Theme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">#color/rides_window_title_bg</item>
</style>
<style name="SetRideTheme" parent="android:Theme">
<item name="android:windowTitleSize">56dip</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
I have what seems to be a problem I can not solve.
protected void onCreate(Bundle savedInstanceState) {
// comments describe what happens
super.onCreate(savedInstanceState);
Boolean customTitleSupported = this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
// crash at underneath line
try
{
setContentView(R.layout.myactivity);
}
catch (Exception e)
{
// You cannot combine custom titles with other title features
}
// never gets to underneath line
if customTitleSupported {
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.override_titlebar);
}
}
...
I use the android-support-v4.jar library
requestWindowFeature(Window.FEATURE_NO_TITLE); does not cause any problems.
...
From AndroidManifest.xml file
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"
/>
<application
android:allowBackup="true"
android:icon="#drawable/replace__logo__app_256_256"
android:label="#string/MicAppName"
android:theme="#style/MicTheme"
android:name="com.example.app.MicApp"
>
From styles.xml
<style name="AppBaseTheme" parent="android:Theme">
<item name="android:windowNoTitle">false</item>
</style>
From my_theme_support.xml
<style name="MicWindowTitleBackground">
<item name="android:background">#android:color/white</item>
<item name="android:padding">0px</item>
</style>
<style name="MicWindowTitleTextAppearance">
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold|italic</item>
</style>
<style name="MicWindowTitle">
<item name="android:textAppearance">#style/MicWindowTitleTextAppearance</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">0</item>
<item name="android:shadowRadius">5</item>
<item name="android:shadowColor">#1155CC</item>
</style>
From my_theme.xml
<style name="MicTheme" parent="AppBaseTheme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">#style/MicWindowTitleBackground</item>
<item name="android:windowTitleStyle">#style/MicWindowTitle</item>
</style>
...
And finally override_titlebar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView android:id="#+id/myTitleLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/replace__logo__app_256_256">
>
</ImageView>
<TextView
android:id="#+id/myTitleText"
android:text="#string/dotdotdot"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
I had missed I had a separate styles.xml for never Android phones which used
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
Replacing that with
<style name="AppBaseTheme" parent="android:Theme.Light">
has made it work