i embedding a code that contains one android:theme with my original code that also have one android:theme, is it possible to have 2 android:theme
I dont now any other way to have this 2 styles.
Androidmanifest.xml
<application
android:theme="#style/AppTheme"
android:theme="#style/AppTheme_1" />
<activity android:name="xxxxxxxxx.RegisterActivity"></activity>
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/color_primary</item>
<item name="colorPrimaryDark">#color/color_primary_dark</item>
<item name="colorAccent">#color/accent_color</item>
</style>
<style name="AppTheme_1" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
You can’t do it in this way (having 2 android:theme).
Depending on your requirements, there can be other ways to achieves.
For example, for most of your screen you want to use your own theme and for certain Activity you want this AppTheme_1, you can try this in that Activity:
public void onCreate(Bundle savedInstanceState) {
setTheme(android.R.style.Theme);
}
No you can't have many themes for same app
but, I suggest do it programmatically using setTheme() method.
with that method, you can replace your themes as you need depending on your needs
you can learn more about themes and styles from here
Related
If i use AppTheme without ActionBar than i get crash when i call WeAccept Payment SDK because they require Actionbar to be available in AppTheme.
My code :
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">#color/DefaultPrimary</item>
<item name="colorPrimaryDark">#color/DefaultPrimaryDark</item>
<item name="colorAccent">#color/DefaultAccent</item>
<item name="android:textColorHint">#color/DefaultPrimary</item>
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And in Manifest
i use android:theme="#style/AppTheme.NoActionBar"
Note : i cant display the default ActionBar in my application because if the custom design
With himanshu help i managed to get it working after creating new theme with different name in styles and adding that sdk activity in my main manifest (it seems that it will override their manifest).
<activity
android:name="com.paymob.acceptsdk.PayActivity"
android:theme="#style/AppThemePayment" />
I am trying to create base theme for whole my app, I have created custom styles for base components like EditText, Button, TextView and wanna to set them globally in my app.
Here is my xml code.
<style name="AppThemeBase" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/base_app_color</item>
<item name="colorPrimaryDark">#color/base_app_color</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:editTextStyle">#style/EditTextBaseStyle</item>
<item name="android:textViewStyle">#style/TextViewBaseStyle</item>
</style>
My custom edit text style
<style name="EditTextBaseStyle" parent="Widget.AppCompat.EditText">
<item name="android:textColor">#color/base_text_color</item>
<item name="android:textSize">#dimen/text_size_edit_text</item>
<item name="android:textColorHint">#color/base_hint_color</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:background">#drawable/edit_text_rounded_corners_bg</item>
</style>
I also tried to use #android:style/Widget.EditText as a parent.
<style name="TextViewBaseStyle" parent="#android:style/Widget.TextView">
<item name="android:textColor">#color/base_text_color</item>
<item name="android:textSize">#dimen/size_text_base</item>
<item name="android:layout_margin">#dimen/margin_text_view_base</item>
</style>
And of course in AndroidManifest.xml file
<application
android:name=".application.QrApplication"
android:allowBackup="true"
android:icon="#drawable/ic_logo_green"
android:label="#string/app_name"
android:theme="#style/AppThemeBase">
<activity
android:name=".ui.activities.LoginActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name"
android:noHistory="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have several questions
Why it doesn't apply style for each view (EditText and TextView), if set style manually in xml layout it works like a charm, but I cannot get it working globally
About style inheritance. There are two types of inheritance explicit or implicit or for user custom styles using . (dot) and using keyword parent for default themes, but what will be if combine this types of inheritance like this <style name="SomeStyle.ParentStyle" parent="Widget.AppCompat.Button">?
Are styles and theme applied to fragments inside activity, theoretically it should because for inflating fragment context from activity is used which is ContextWrapper ?
Please if you have any ideas what can cause such problem, help to solve it or at least share your thoughts.
Thanks.
The problem was solved
Instead of overriding
<item name="android:editTextStyle">#style/EditTextBaseStyle</item>
I have to override
<item name="editTextStyle">#style/EditTextBaseStyle</item>
To figure out what style item you need to override, follow the inheritance tree of base style/theme and you will find what is the name of style item you need to use.
BUT NOTE
Text view style should be still
<item name="android:textViewStyle">#style/TextViewBaseStyle</item>
It is weird but as is.
My app has a Light Material Theme, but one section of my activity is dark, and I've placed a SearhView in it. The problem is then that the search icon hint is black-on-blue. Not pretty. So can I override the theme for this single View only?
The intuitive thing to do would be to change the style proerty. So I tried this, to no avail:
<SearchView
style="#android:style/Widget.Material.SearchView"
(...)
/>
(the normal style would be Widget.Material.Light.SearchView, I suppose)
Suggestions?
PS: I am not going down this rabbit hole
You can set it in your manifest. You can globally define a theme for the whole application but you can apply other themes for activities too.
For Application:
<application
android:name=".MyApp"
android:theme="#style/Theme.global">
For Activity:
<activity
android:name=".SomeActivity"
android:theme="#style/Theme.search">
UPDATE on comment:
Then set this in your styles.xml where you define your theme attributes like this:
<item name="android:searchViewStyle">#stye/MySearchViewStyle</item>
This is the default for base Searchview:
<style name="Base.Widget.AppCompat.SearchView" parent="android:Widget">
<item name="layout">#layout/abc_search_view</item>
<item name="queryBackground">#drawable/abc_textfield_search_material</item>
<item name="submitBackground">#drawable/abc_textfield_search_material</item>
<item name="closeIcon">#drawable/abc_ic_clear_mtrl_alpha</item>
<item name="searchIcon">#drawable/abc_ic_search_api_mtrl_alpha</item>
<item name="searchHintIcon">#drawable/abc_ic_search_api_mtrl_alpha</item>
<item name="goIcon">#drawable/abc_ic_go_search_api_mtrl_alpha</item>
<item name="voiceIcon">#drawable/abc_ic_voice_search_api_mtrl_alpha</item>
<item name="commitIcon">#drawable/abc_ic_commit_search_api_mtrl_alpha</item>
<item name="suggestionRowLayout">#layout/abc_search_dropdown_item_icons_2line</item>
</style>
You can define your style like this:
<style name="MySearchViewStyle" parent="Base.Widget.AppCompat.SearchView">
<item name="searchIcon">#drawable/my_incredable_search_icon</item>
</style>
I was able to create a floating activity after following this tutorial http://cases.azoft.com/android-tutorial-floating-activity/
However, to do so, I had to add this line in styles.xml :
<item name="android:windowIsTranslucent">true</item>
Is it possible to have the same effect using only Android/Java code ? (e.g. in Activity.onAttachedToWindow() or so...)
Thanks in advance for your help.
[EDIT 01] styles.xml must not be changed (and I'm not supposed to know what's in it...). But for testing purposes, I'm using the default one:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
[EDIT 02] Resources.Theme.applyStyle() seems to do what I want (according to the API description: "Place new attribute values into the theme" ).
So I created the following custom_style.xml :
<resources>
<style name="MyCustomStyle" >
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
Then, in onAttachedToWindow() , I called:
getTheme().applyStyle(R.style.MyCustomStyle, true);
But it didn't have any effect...
Is it possible to have the same effect using only Android/Java code ?
I am afraid, No. You will have to do it in styles.xml only. AFAIK value of android:windowIsTranslucent alone can't be changed programatically.
When we call super.onCreate(savedInstanceState); the Activity class provides empty graphical window on which we set our content ie.views. And a theme is applied to this window and then the content are loaded on this view.
Hence the sequence will be,
call to super.onCreate()
setting theme for the activty.
seting the content views for that activity.
eg.
styles.xml
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowBackground">#drawable/background</item>
<item name="android:windowNoTitle">true</item>
</style>
<!-- Application theme.without title bar -->
<style name="AppTheme.NoTitleBar" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowBackground">#drawable/background</item>
<item name="android:windowNoTitle">true</item>
</style>
<!--Floating activity theme -->
<style name="Theme_Translucent" parent="android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowFullscreen">true</item>
</style>
Then set your theme for Floating activity as follows:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_Translucent); // Set here
setContentView(...)
}
do this
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window w = getWindow(); // in Activity's onCreate() for instance
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
Can't say about to do this programatically .. but if you need to do this you can give a try like this ..
Add theme to you activity in manifest file like this ..
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
Example :-
<activity
android:name="com.example.androidhackerphonelocker.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Hope it solves some problem of your's ..
Maybe this can help.
#Override
protected void onCreate(Bundle savedInstanceState) {
processSetTheme(this);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawableResource(R.color.realTranslucent);
if (Build.VERSION.SDK_INT>=19){
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
super.onCreate(savedInstanceState);
<color name="realTranslucent">#00000000</color>
There a new method appeared in Android R
if android.app.Dialog
window.setDimAmount(0f)
window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
In my Android app, I am using various custom themes in different activities, all of which work fine. All these themes use the same custom styles for buttons, edit controls etc.
My preferences use standard Preference activities, which I define in XML and style via the manifest.
However, when I have a preference that causes an alert dialog to get launched, for example a ListPreference, the dialog uses the standard buttons. It does seem to use my custom EditText style in the EditTextPreference... but not my background or text colour.
Anyone have any idea why this is happening ?
Some of the code:
Styles:
<style name="Theme.Prefs" parent="#android:style/Theme.Holo.Light">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:buttonStyle">#style/CustomButtonStyle</item>
<item name="android:editTextStyle">#style/CustomEditTextStyle</item>
</style>
<style name="CustomButtonStyle" parent="#android:style/Widget.Holo.Button">
<item name="android:background">#drawable/custom_button</item>
<item name="android:textSize">#dimen/dialog_text_size_normal</item>
<item name="android:textColor">#color/dialog_control_colour</item>
</style>
<style name="CustomEditTextStyle" parent="#android:style/Widget.Holo.EditText">
<item name="android:background">#drawable/custom_textfield</item>
<item name="android:textColor">#color/dialog_control_colour</item>
<item name="android:textSize">#dimen/dialog_text_size_normal</item>
</style>
And in the manifest:
<activity
android:name="com.breadbun.prefs.MainPreferencesActivity"
android:theme="#style/Theme.Prefs"
android:screenOrientation="portrait">
</activity>
To customize the alertDialog you need to add the second row to your main theme, and then customize the DialogStyle the way you want it.
<style name="AppTheme" parent="android:Theme.Material">
<item name="android:alertDialogTheme">#style/DialogStyle</item>
</style>
<style name="DialogStyle" parent="android:Theme.Material.Dialog.Alert">
</style>