I build an app with four tabs and, as a consequence, four fragments. In the first fragment, I have a sliding menu and I throw with a custom icon in the actionbar. The problem is that in the others fragments, I want to stablish other custom icon to return to the first fragment but I don't know what to do...
This is my styles.xml with my custom icon for the sliding menu:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:homeAsUpIndicator">#drawable/menu32</item>
</style>
The java code works well but I don't know how to change the icon dynamically.
This is what I have:
You can use the following in your fragments:
Actionbar ab = getActivity().getActionBar();
ab.setIcon(icon);
Where icon is a Drawable or a resource id, when the up indicator is a part of your icon.
You can also use setHomeAsUpIndicator if you use API level > 11:
getActivity().getActionBar().setHomeAsUpIndicator(resId);
If your API level is lower, then I suggest you make use of ActionbarSherlock.
Related
Using iccube 5.2, we developped a custom widget that needs quite BIG data download...
Unfortunately, when loading a report containing this widget, nothing is shown on the screen until it is loaded and users may think nothing happens...
How could I advise the user it is working, and he just has to wait ?
There are predefined styles for such case.
<div class="ic3-fixed-layout-box ic3-loading" style="width:200px; height:200px">
<div class="ic3-loading-div-back"></div>
</div>
This html will result in 200x200 px box with loading animation and blur effect.
So, to see loading effect class .ic3-loading should be added to the widget's parent container (with class .ic3-fixed-layout-box) while request is loading.
Check that your widget spawns with these classes before request send, and on request success just remove .ic3-loading class from parent element just like it is done for ic3 widgets.
I'm looking for a way how I can change the font of the title in the actionbar before starting the main activity.
My current approach to change the font is the following:
int titleId = getResources().getIdentifier("action_bar_title", "id","android");
TextView textView = (TextView) findViewById(titleId);
textView .setTypeface(Typeface.createFromAsset(getAssets(), "my_font.ttf"));
This block of code is executed at the beginning of the onCreate method of the main activity. Actually, this works pretty well.
However, the small imperfection is only that when the application is launched, the title appears for a very short time in the default font before it changes. In my activity I use the DrawerLayout.
How can I change this behavior so that the text is displayed from the start in the right font?
Thank you for your help.
This is probably not possible. At least I have not found a way to accomplish this.
But I found a workaround that provides the same effect: You can design an image with the title and then define it in the styles.xml as the logo, for example:
...
<item name="android:logo">#drawable/ic_logo</item>
...
When the application is started up, the logo with the title can be removed again. As far as I've seen other apps (eg runtastic) use this technique as well.
To briefly explain my goal : I'm building an app to a public terminal on android. I'm trying to avoid the top finger pull Status/Notification Menu by the android os. I have not been able to prevent this Menu mechanism programmatically. To accomplish this goal, I'll have a custom made enclosure that'll cover top part of the screen for the android device. Enclosure will also cover home, back buttons.
I'm using android ActionBar (not Sherlock). Obviously the ActionBar tabs needs to move down a little to make room for the covered part by the enclosure. I set paddings for the actionbar through Theming.
Here is corresponding part of /res/values/themes.xml (AndroidManifest.xml is already set to use CustomTheme)
<style name="CustomTheme" parent="AppBaseTheme">
<item name="android:actionBarTabStyle">#style/MyActionBarTabStyle</item>
<item name="android:actionBarSize">#dimen/action_bar_default_height</item>
</style>
<style name="MyActionBarTabStyle" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:paddingTop">#dimen/actionbar_paddingtop</item>
</style>
This works as expected in landscape mode. In portrait mode paddingtop will work, but action bar height will not adjust (actionBarSize don't work), so the ActionBar tab text will get cut off.
At first I tought dimen files could be the problem. I've tried generating /res/values-port copies of themes.xml and dimens.xml, but doesn't seem to be the problem. padding works after all. I've also tried putting in direct values like 90dp for actionBarSize, and 32dp for padding without any luck.
To me it appears portrait mode does not like actionBarSize. There is no similar question on the web related to this issue, maybe I'm missing something simple. Any help is appreciated.
This may be already too late to answer your question. I will just put this here.
Apparently, this is a bug from android sdk, check this link.
https://code.google.com/p/android/issues/detail?id=41792
How can I change the application icon on mouseover? I want to put some menu items in the system menu of my CDialog, and I want the icon to highlight when the user mouses over it to indicate that it is a user interface component (similar to how recent versions of firefox have the firefox menu in orange and when you mouseover it, it highlights).
UPDATE
By "application icon" I mean the system menu icon. Also I just came across the CMFCRibbonApplicationButton class which, while not the system menu, also looks promising.
Check WM_NCHITTEST for HTSYSMENU code and then call SetIcon.
There is the code to implement MouseOverEvent: http://www.codeproject.com/KB/cpp/mouseenterleave.aspx When you catch the event you can do whatever you like.
Designing UIs with QtCreator under Windows, and porting the same .ui file under MacOSX leads to designs with some text parts very small -- actually, the HTML ones. It seems it comes from the fact that QtCreator uses pt instead of px as text size unit, and that the default screen resolutions are quite different under Windows and MacOSX.
Is there any reason I didn't come to more consistent results? Apart from editing each pt into px, are there any workaround?
Thanks.
As a rule of thumb you should not specify the font sizes for controls manually in Qt Designer/Creator as this leads to the prolems you have. The reason for inconsistency is the fact that different platforms use different DPI settings (96 dpi on Windows vs. 72 DPI on Mac OS X).
This results in fonts being displayed with different sizes.
Also, you mentioned HTML. I assume you have set some HTML text in a QTextEdit-like widget using the built-in editor. When you select a font size there, Qt Creator will produce some HTML like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Sans'; font-size:11pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Hello World</p></body></html>
As you can see, it sets some font-size attributes, which is really nasty. A simple, easy solution to this desaster is to remove the style= attributes entirely. This causes the QTextEdit to use the default application font instead (which should be fine on all platforms):
<html><head></head><body><p>Hello World</p></body></html>
As a sidenote, this is much friendlier for translators, as they don't have to fight through all the useless CSS.
Unfortunately Qt's QTextEdit does not support the "percent" font-size specification (just px and pt). If it did, you could have used something like "90%" to make the text smaller than the default font while still being on the safe side.
Another option would be a QWebView, which you make editable. This allows for good text formatting while having the full CSS subset. But that might be overkill.
Hope that helps!
Do you have to set text properties in you .ui files? Usually when you set the text property of a widget then UIC replaces completely the Font of that widget with something that it creates from scratch in code. If you edit them on windows then the font will have a windows related name which might cause problems on the mac.
What I usually do is not to touch the fonts in the designer so that the widgets get their defaults fonts which usually look fine and change them in the c'tor of the widget like so:
QFont f = ui.someLabel->font(); // get the current (default) font from the widget
f.setBold(true); // change only what's need to be changed
ui.someLabel->setFont(f);
// set the new and impreved font back to where it came from
This way you can avoid messing with anything that is platform specific.
If your change is actually platform specific you can choose the right one with the use of #ifdef Q_OS_WIN32 or #ifdef Q_OS_MAC