Old / dark dialog boxes when using TStyleBook - android

This problem is highly related to the following question: Why are all the dialogs are using the "old" Android 2.x style?
I'm using Delphi Berlin (10.1), where this problem has been fixed already:
But, as soon as a TStyleBook is dropped to the form and assigned to it (e. g. by right clicking a component and then "edit custom style"), the dialog boxes (all of them) turn to the dark style again:
The automatically created "trimmed" style is still the "light" version ("AndroidL Light"). And yes, I checked that function "GetNativeTheme()" in FMX.Helpers.Android.pas assigns the Result, I even copied the file and added it to the project. Removing the assignment from Form1.StyleBook show the native styled dialogs again.
How can this be solved while still keep using a TStyleBook?

I found the problem: Function GetNativeTheme() was searching with TStyleManager.FindStyleDescriptor() in the assigned style for a TStyleDescription object entry, to look if one of the strings "[LIGHTSTYLE]" or "[DARKSTYLE]" is used for the target platform. In a full style file this object entry is normally present, but when starting to edit a custom style of a component inside the IDE, a TStyleBook component is created with just a small style. It cannot be seen inside the IDE, but this small style does not contain the TStyleDescription object entry, so the dark/light theme can not be found out. And by default, the GetThemeFromDescriptor() returns 0, which seems to correspond to the dark/old style.
I solved the problem by double-clicking the TStyleBook component, save the style to a file (*.style), opened the file in a text editor and simply manually added the TStyleDescription object entry. Saved and loaded back to the IDE. Now all dialogs use the correct light style theme.
Here again as text:
object TStyleDescription
StyleName = 'Description'
Author = 'Embarcadero Technologies Inc.'
AuthorURL = 'www.embarcadero.com'
PlatformTarget = '[ANDROID][ANDROIDL][LIGHTSTYLE][DEFINEFONTSTYLES]'
MobilePlatform = True
Title = 'AndroidL Light'
Version = '1.0'
end

In addition to StanE's answer:
Instead of adding a StyleDescription to all custom styles you can also modify the GetThemeFromDescriptor() function in FMX.Helpers.Android to return a default value of TJAlertDialog.JavaClass.THEME_HOLO_LIGHT.

Related

Android Studio 1.2.1.1 - Failed to find style 'textViewStyle'

I'm new to Android development and I just installed Android Studio version 1.2.1.1. I created a project, HelloWorld, and chose the default blank activity, Darcula theme, and default API. Straight out of the box, without having written any code or touched anything, I get this message:
"Rendering Problems
Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. Failed to find style 'textViewStyle' in current theme (4 similar errors not shown)."
I uninstalled and reinstalled Android Studio but I still get this error so I'm not sure what else I should do. It says "use the theme combo box... or fix the theme style references" and I'm new to Android Studio so I have no idea where the box is or how to change the reference.
Simply click on the Refresh icon at the review pane:
Android gives you the option to define your own style format, which the default project you made did. It created a style named 'textViewStyle'.
If you look at the text view instead of the design view (you can switch by pressing the tab at the lower left in the part where you get the error that it can't render) you will see that the textView or the app itself contains a line android:theme="#style/textViewStyle".
You can either remove this line, or track down the error in the styles.xml file in the res/values folder. This is the file that defines the style for the app.
If this doesn't help you it could be that the style is defined in your AndroidManifest.xml file, look at the tag, it will contain a line saying android:theme="#android:style/textViewStyle", change that to android:theme="#android:style/Theme.DeviceDefault" and you should be good to go.
More info on custom themes: http://developer.android.com/guide/topics/ui/themes.html
Since you are a beginner, more on general Android development:
http://developer.android.com
Make sure to select the correct theme from the menu in the preview panel.
If you set the layout file to be FullScreen in the manifest but select something like NoActionBar theme in the preview panel, you will also get this error.
Go to manifest file, check the theme you are using there and pick the same in the Design view of your xml file.
Rebooting Android Studio did the trick for me. I couldn't find the "Refresh" button in the accepted answer for some reason.
Click on "Design" tab
On the right pannel, search for the objet "text" that contains something like "#string/hello_world"
Remove this value from the field
There's no more error.

Android upper Copy/Paste toolbar

I need your assistance with the following issue in android dev.
For some reason when I extend ActioBarActivity the cut/copy/paste buttons are displayed correctly when I press the EditText component (see image 1).
Unfortunately, if I extend Activity, the toolbar is not displayed correctly. You can see on image 2, that the buttons are present but they are white and the user cannot see them. I have investigated but I'm not sure how to fix this.
If you need I can share the code but I think this can be easily reproduced.
Thanks in advance.
Paul
Try using this in the definition of your app theme:
<item name="actionModeBackground">#color/actionBarBgColor</item>
Create a custom style and specify the background to the color you want, and in your theme xml resource file, between the "style" element, set the "android:actionBarStyle" to the custom style you just created, it'll change the action bar color for you.
Updated: I just used the default folder for my theme resource (Note: the file name is arbitrary), if you want to create a theme resource for v-11 (API level 11) and up, create a new theme resource file (again, file name is arbitrary) with a "-v11" suffixed to the name of the file.
This is the default theme resource file since it inherits properties and attributes from the Theme.AppCompat.Light.DarkActionBar, as you can notice, in this file, you MUST not use the "android" namespace. If you have another theme resource file, like in the picture above, Android Studio automatically created the stylex.xml(v21) which is for Android version 21 and up devices. You MUST add the "android" namespace to each and every attribute such as the actionBarStyle would become android:actionBarStyle, but you should now that, the ActionBar has been deprecated since version 21, API level 5.
Also, the displayOptions attribute tells Android about how the title area is shown. These are availabe values:
none
useLogo
showHome
homeAsUp
showTitle
showCustom
disableHome
Note: the background attribute ONLY accepts reference value, not hard-coded value.
Here is the result

Changing app theme at runtime using using external theme file

I want to produce a single app that would let the user select a theme and have this applied over the entire app.
I understand that this can be achieved by using setTheme in onCreate of each activity.
But I need this to work in a different way. I don't want to have the themes stored in theme.xml or styles.xml.
I want to have a list of themes stored on the web and be able to dynamically download a new theme and have it applied in the app. I want to be able to create new themes without having to build a new version or an updated version of the app.
Images would be easy to replace. Just download from a url and store locally to be re-used. But the actual theme of the app, the colours of buttons etc should be changed at run time from a theme.xml file which isn't part of the apk but is fetched online.
Is this possible?
It depends how much styling you want to be able to do. You currently can't set view items styles grammatically outside of using a resource. But you can control things like text color and background color. If that's all you need to change, I would recommend writing a Theme factory class for you app that you use to get each view element you need. For example a getButton() function that will return you a button with the background color and text color you need.

Android visual editor doesn't allow editing

Properties in the Outline-view are mostly in seemingly disabled state, while using Android visual editor. Only those properties, which already had some content when opening a layout-file are available for editing. Others might pop up some window when clicked, but even after selecting something nothing gets changed.
There doesn't seem to be anything meaningful to update via Android SDK Manager or among the Eclipse-plugins. I'm using Eclipse 3.7. What's wrong with the editor?
Android Visual editor properties http://hoito.org/kuvat/toisaanne/eclipse-androidvisualeditor-properties.png
If the property line has gray background (what you describe as "disabled"), it means that property has the "default" value set. In that case, no attribute entry is set in the xml.
If you select multiple elements, properties are shown gray if none of the elements has that property set, white and empty if the property is set by some but not all elements, and white with text when all selected elements have the same value. Note that multi-selection only works properly when you use the "sort alphabetically" button.
At times, the property editor can be a bit unwilling, but if you double click an entry shown in the popup, or press enter when selecting a proposed value, the property should be set.

Consistent UI color in all Android devices

I noticed the UI color (eg Button background/text color) all changes from device to device, based on the current theme that is being used in a device.
What is the best practice to apply custom UI colors for Android app, so that I have same color scheme for my app in all Android devices. I can set text/background color on a UI item. I'm wondering if there is a single place where I can define all the colors which will override the current theme applied on the phone.
thx.
Yes, there is a single place where you can define these values for your app. See Styles and Themes in the Android docs for how it works.
A style is just a mapping of values to predefined names. If you find yourself repeating a number of common attributes in your layouts, you can factor that out into a style. For example, you might have a special button style that defines a specific background and text color.
A theme is a sort of meta-style. It can be applied to an Activity or even a whole application through your AndroidManifest.xml. Among other things it defines the default styles for widgets and values that control other parts of the look and feel for your UI.
When you're trying to blend in with the system in an otherwise custom UI for your app, you can query the current theme for values. Just like you use the # reference syntax #android:drawable/foo when referring to a system resource, you can use the syntax ?android:attr/foo when you want to use the value stored in the system theme attribute foo.
In your case, if you want to change the primary text color across your app, apply a custom theme that sets the attribute textColorPrimary. If you just want to be sure that an element of your app is using the primary text color as defined by the device your app is running on, you can set android:textColor="?android:attr/textColorPrimary". The same principles apply elsewhere as well.
If you want to see what attributes are used in the system, they are defined as part of the Android framework in this file: frameworks/base/core/res/res/values/attrs.xml. Look at the children of the XML element <declare-styleable name="Theme"> at the top. To see examples of what the system sets these to, see themes.xml in the same directory. Finally, not all of these attributes are public - non-public attributes cannot be set by an app, they're implementation details of the Android framework. See public.xml for the complete list of which attributes are available for use in apps.
Best practice is to apply a custom theme to your application, and override as much of the default properties as you need.
Almost everything can be changed, except
The Menu
Some properties of AlertDialog (these can be changed using a custom dialog)
OS provided views such as the Quick Search Bar (QSB)
If you like the look of the default SDK resources then you can find these in sdk_folder/platforms/android-9/data/res/ (replace 9 with the SDK version you want the resources from) - copy the ones you want into your App and reference those.
You can take a look at the theme the SDK uses:
themes.xml
styles.xml

Categories

Resources