Customise app title - android

I am trying to implement custom app title. I made a custom layout to change the title text color to white.
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="0dp"
android:text="#string/title_activity_main"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/textColorWhite"/>
And in the activity onCreate()
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.activity_home);
setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.my_icon);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.layout_custom_app_title);
It fails to work on Android 2.2 device. However, I tested successfully on version 4.0
Does anyone got any workaround?
EDIT:
<style name="customWindowTitle">
<item name="android:textColor">#color/textColorWhite</item>
</style>
<style name="LightThemeSelector" parent="android:Theme.Light">
<item name="android:windowBackground">#drawable/app_background</item>
<item name="android:textColor">#color/textColorBlack</item>
<item name="android:windowTitleStyle">#style/customWindowTitle</item>
</style>

you can do this easily by using custom theme. To do so here is the procedure
in style.xml add
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#color/textColorWhite</item>
// here you can add other attributes
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">25dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
</resources>
and in AndroidManifest.xml add
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#style/CustomTheme">

Related

Titanium - Hiding Android actionBar for specific window

I'm trying to hide the actionBar for a specific window. I've followed this: http://www.appcelerator.com/blog/2014/08/hiding-the-android-actionbar/ which used to work for me in the past.
What I did was to create a custom theme like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.NoActionBar" parent="#style/Theme.AppCompat">
<item name="android:windowNoTitle">true</item>
</style>
<style name="Theme.YesActionBar" parent="#style/Theme.AppCompat">
<item name="android:windowNoTitle">false</item>
</style>
</resources>
I've set the following in my tiapp.xml:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
</manifest>
</android>
And I've set the following in my window tss:
"Window[platform=android]" : {
theme: 'Theme.NoActionBar'
}
but still the action bar shows. If I hide it from code on window open event than it cuts the background image I have - so I rather do it with a theme.
how can I hide action bar with theme on sdk 5.2.0?
I was able to solve the problem by changing my custom theme to this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.NoActionBar" parent="#style/Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.YesActionBar" parent="#style/Theme.AppCompat">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
</style>
</resources>

How to change the floating label color of TextInputLayout

I am implement floating label as per material design . Now i want to change the color of few elements like change the color of default hint (Email id which black right now) and line below it
.
I have gone through similar question like these but couldn't solve my problem .
<resources>
<style name="AppTheme" parent="AppTheme.BaseTheme"></style>
<style name="AppTheme.BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="Signin_EditText" parent="TextAppearance.AppCompat">
<item name="colorAccent">#color/white</item>
<item name="colorPrimary">#color/white</item>
<item name="android:editTextColor">#color/white</item>
<item name="colorControlActivated">#color/white</item>
<item name="colorControlHighlight">#color/white</item>
</style>
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout_email"
android:layout_width="match_parent"
app:hintTextAppearance="#style/Signin_EditText"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edittext_emailid"
android:layout_width="match_parent"
android:textSize="14sp"
android:minHeight="35dp"
android:layout_height="wrap_content"
android:textColorHint="#color/white"
android:inputType="textEmailAddress"
android:textColor="#color/white"
android:hint="#string/emailid"/>
</android.support.design.widget.TextInputLayout>
Try this.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorControlNormal">#color/primary_light</item>
<item name="colorControlHighlight">#color/primary_light</item>
<item name="colorControlActivated">#color/primary_light</item>
<item name="colorAccent">#color/primary_light</item>
<item name="colorPrimary">#color/primary_light</item>
<item name="colorPrimaryDark">#color/secondary_dark</item>
</style>
Change your colorAccent to the required color.
You can't Override the Colors colorAccent, colorPrimary, colorPrimaryDark or any other colors which are used for Theme by AppCompact. You can only Define them in Application Theme which you will in use in Manifest file.
If you want Customize your theme colors, you have to define them in BaseTheme which you are using in Manifest file <application... tag as below
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorControlNormal">#color/primary_light</item>
<item name="colorControlHighlight">#color/primary_light</item>
<item name="colorControlActivated">#color/primary_light</item>
<item name="colorAccent">#color/primary_light</item>
<item name="colorPrimary">#color/primary_light</item>
<item name="colorPrimaryDark">#color/secondary_dark</item>
</style>
Manifest file:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...
</application>

how to change title color of toolbar in pre-lollipop versions of Android

I am learning to design Android apps using new Material Design themes. And while designing a custom ToolBar I was trying to give a custom color to the title inside the my custom ToolBar.
On Android Lollipop device it is working fine as expected, as you can see in the image link given below, but when i tried it to run on the pre-Lollipop device, I am not getting the same result. Why so? I have attached the code below.
Here I have attached the screenshot of both, Lollipop version as well as pre-Lollipop version screens.
Lollipop version which shows it correctly
pre-Lollipop version which is not giving the expected output.
Code:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar" />
<TextView
android:layout_marginTop="10dp"
android:layout_below="#+id/app_bar"
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#455A64</item>
<item name="colorPrimaryDark">#607D8B</item>
<item name="colorAccent">#9E9E9E</item>
</style>
<style name="CustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#D32F2F</item>
<item name="android:textColorSecondary">#F44336</item>
</style>
</resources>
app_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1976D2"
android:theme="#style/CustomToolbarTheme"
android:popupTheme="#style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
P.S.: If this Question (or similar) is already been answered here, then please comment the link here. Thank You!
You're using
android:theme="#style/CustomToolbarTheme"
which is this:
<style name="CustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#D32F2F</item>
<item name="android:textColorSecondary">#F44336</item>
</style>
It's not overriding the colorPrimary attribute like AppTheme.Base is. Add that line to this style and make sure the background is set to it, like this:
<style name="CustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:background">?attr/colorPrimary</item>
<item name="colorPrimary">#455A64</item>
<item name="android:textColorPrimary">#D32F2F</item>
<item name="android:textColorSecondary">#F44336</item>
</style>
Try set titleTextAppearance for your Toolbar's theme, like this:
<style name="Toolbar" parent="Theme.AppCompat.Light">
<item name="titleTextAppearance">#style/Toolbar.TitleText</item>
</style>
<style name="Toolbar.TitleText">
<item name="android:textColor">#color/toolbar_title_text</item>
</style>
EDIT:
Sorry, I forgot to add that you should set one more thing.
<android.support.v7.widget.Toolbar
...
xmlns:app="http://schemas.android.com/apk/res-auto"
app:theme="#style/Toolbar"
app:titleTextAppearance="?attr/titleTextAppearance"/>
(Solution above can be used also for other text appearance's attributes, for example android:textStyle or android:textSize.)
if it not working then you can also set toolbar custom title colour and toolbar custom title at runtime. Code snippet is given below
private Toolbar toolbar;
toolbar = (Toolbar) findViewById(R.id.app_bar);
toolbar.setTitleTextColor(Color.parseColor("#FF557F"));
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Title");
I'm using this:
color.xml
<resources>
<color name="white">#fff</color>
<color name="primary">#673ab7</color>
<color name="primary_dark">#512da8</color>
<color name="accent">#ffc400</color>
<color name="text_primary">#009688</color>
<color name="text_secondary">#e2eef0</color>
</resources>
values/themes.xml
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/text_primary</item>
<item name="android:textColor">#color/text_secondary</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
</resources>
values-v21/themes.xml
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<item name="android:colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/text_primary</item>
<item name="android:textColor">#color/text_secondary</item>
<item name="android:navigationBarColor">#color/primary_dark</item>
</style>
</resources>
See some tutorials:
material-design-everywhere
Android L Tutorials (Part 2): Material Theme Colors
you use this on your theme android:textColorPrimary , so instead use this textColorPrimary because the first is using just in v-21 on lollipop

Applying buttonStyle via theme wouldn't work, applying directly works perfectly

I am having problem applying button style to the theme but applying to the button directly works perfectly. Any idea what's the problem here?
themes.xml
<style name="Theme.AppTheme" parent="#style/Theme.Sherlock.Light.DarkActionBar">
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
</style>
styles.xml
<style name="ButtonAppTheme" parent="#android:style/Widget.Button">
<item name="android:background">#drawable/btn_default_holo_light</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">64dip</item>
<item name="android:textColor">#000000</item>
</style>
AndroidManifest.xml
<Application
android:name=".ThreesixtyusApp"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/Theme.AppTheme" >
Applying button style directly works:
<Button
android:id="#+id/like"
android:layout_width="100dp"
android:layout_height="wrap_content"
style="#style/ButtonAppTheme"
android:text="#string/like" />
This looks generated. Did you forget about the styles/themes in the values-v11 or values-v14 folders?

Android style specify button color

I am trying to apply a button text color by default in styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme">
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#color/black</item>
<item name="android:textColor">#color/green</item>
</style>
How do I make the style change button color, and apply throughout the entire application? My mainfest includes:
<application
android:icon="#drawable/ic_launcher"
android:label="Hack the World"
android:theme="#style/AppTheme">
This changes all text (such as a TextView), but does not change the text in a button. If I use the ColorThemes style from above and place it in the xml for the button like this:
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="loadSavedgame"
android:text="Load Saved Game"
android:textColor="#color/green" />"
Then it works perfectly. Why doesn't this apply universally because of the style? All different versions of styles.xml have the same code.
I eventually discovered that a button is, in fact, a 9-patch image that is located at #android:drawable/btn_default in order to change the background you must modify this image. In order to change button text color I had to set a button widget style and import it into my app theme like so:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" >
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#color/black</item>
<item name="android:textColor">#color/green</item>
<item name="android:buttonStyle">#style/ButtonText</item>
</style>
<style name="ButtonText" parent="#android:style/Widget.Button">
<item name="android:textColor">#color/green</item>
<item name="android:background">#android:drawable/btn_default</item><!-- only way to change this is to change the src image -->
<item name="android:layout_width">80.0px</item>
<item name="android:layout_height">40.0px</item>
</style>
</resources>

Categories

Resources