I am developing an IME for android.
i have the options of setting the theme for the keyboard.
the problem when i try to inflate the keyboardView a second time it it did not work
KeyboardView k = (KeyboardView) getLayoutInflater().inflate(R.layout.input1, null);
it change just when i re-runing the app .
it seems is just changed when the my InputMethodeService recreated but i did not found a way to stop it and start the service again.
Plz Help
I found a solution to my problem.
My real problem is to inflate the same view ( KeyboardView ) multiple time.
I tried to change my parent view from KeyboardView to a RelativeLayout and for each keyboardveiw Theme i Remove all the parent child and i add the new keyboardview infalted with the new Theme.
Related
In other words,LayoutInflater.from(...).inflate() require either a XmlPullParser or an Resource Locator. How can I instruct it to inflate a default View such as a TextView or a Button ?
Well, turns out that on runtime, the instantiation of a View object already inflates it.
In the end, the whole expression:
LayoutInflater.from(...).inflate()
can be replaced with the widget itself:
TextView(parent.context) (for a TextView)
In Android, say if I dynamically create a TextView with:
TextView view = new TextView();
and add it to the root view of an activity. Does this view inherit theme properties such as text color?
If so when does this happen? At the time of its creation or the time of adding the view?
As #zapl said, use new TextView(context). Also, make sure you use the activity context to inherit the activity's theme/style instead of application context.
I just started playing with the new support library with ActionBar support. I'm trying to implement a bar that looks basically identical to the Ice Cream Sandwich layout on the edit contact screen. I understand I probably need to implement a custom view something similar to this - How to display custom view in ActionBar?. What I don't understand is exactly what that view is, and the best way to implement it.
Here's the screenshot of what I want in my actionbar:
Is that just a view with an image and some text, or a styled button, or something totally different? It has some state pressed properties.
Thanks for the help.
You can try using a custom view, by adding the following code when you want the button to appear :
// Inflate the view from XML file
LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.search, null);
// Tell the view to occupy the whole actionBar view (MATCH_PARENT)
LayoutParams layout = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
getActionBar().setCustomView(v, layout);
i am inflating the layout using the layout inflator which had 10 editext field, when i click on the edittext soft keyboard hides the edittext if me does not inflate the layout and place in the setcontentview it workis fine. if a put requestfocus tag with inflating the layout crash the app. please find the below code and help me to resolve this.
JAVA CODE
LayoutInflater inflater = LayoutInflater.from(this);
scrollView = (MyHorizontalScrollView)
inflater.inflate(R.layout.horz_scroll_with_list_menu, null);
setContentView(scrollView);// if i comment this and add inflatelayout SetContentView(R.layout_details) works fine.
menu = inflater.inflate(R.layout.horz_scroll_menu, null);
app = inflater.inflate(R.layout.details, null);//
You may need to change an attribute in your manifest (for your Activity) to handle this. Put this line in your AndroidManifest.xml (within the tag you use to define your Activity)
android:windowSoftInputMode="adjustResize"
First of all thanks everyone who tries to reply this topic.
I have an activity and I wanted to show a sort of menu at the top of the screen and I used windowmanager to handle this. it was about UI issues I encountered why I choise windowmanager to do such a menu. But for now I want this menu to animate but it seems animation takes no effect. Here is my code.
If anyone has any idea how to animate windowmanager I ll be appreciate.
Animation animShowTopLine;
animShowTopLine = AnimationUtils.loadAnimation(this, R.anim.translate);
animShowTopLine.reset();
LinearLayout top_line;
WindowManager wm;
WindowManager.LayoutParams wmParams;
LayoutInflater inflate = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
top_line = (LinearLayout) inflate.inflate(R.layout.line, null);
wm =(WindowManager) getApplicationContext().getSystemService("window");
wmParams =new WindowManager.LayoutParams();
wmParams.type=2002;
wmParams.format = 1;
wmParams.flags=40;
wmParams.width=WindowManager.LayoutParams.FILL_PARENT;
wmParams.height=WindowManager.LayoutParams.WRAP_CONTENT;
wmParams.gravity = Gravity.TOP;
wm.addView(top_line, wmParams);
top_line.startAnimation(animShowTopLine);
Thanks in advance. Regards.
First, please for your own sanity don't hard-code a bunch of constants like that. The name of the window manager service is Context.WINDOW_SERVICE. The window type is WindowManager.LayoutParams.TYPE_PHONE. The flags you have set is... ummm... WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE (seriously, written in decimal as well??). The format is PixelFormat.RGBA_8888 (and I would strongly recommend using PixelFormat.TRANSLUCENT instead).
Now, first, what in the world are doing using TYPE_PHONE? You don't want to do that. If you want a window layered on top of your main window, you should be using TYPE_APPLICATION. In fact, I would urge you to just use Dialog for this and set its attached window to be what you want. It will take care of all the details of working with the window manager, and doesn't limit you in any way with how you can animate it.
I think the main problem you have here is that you are trying to animate the root view of the window. The root view is somewhat special -- it defines the top-most part of the window, exactly matches the window, and is always forced to be the size of the window. It is what drives the layout of its child windows. If you want to do a view animation, you should leave the root view alone (it is the anchor of the window) and animate the elements inside of it.
That said, since you are using an old-style animation, there is a better way to animate full windows, the way that the system animates dialogs and activities and such: set the animation in the window's layout params. Then the window manager will apply that animation to the entire window surface as you specify. This is more efficient than doing it inside of the window because each frame of the animation only requires re-compositing the screen with the new animation transformation, instead of re-drawing the window contents and then re-compositing it.
You do this by setting WindowManager.LayoutParams.windowAnimations. This is an integer field that takes the resource id of a style resource defining the various animations associated with the window. For example, the style used for the standard dialogs is:
<style name="Animation.Dialog">
<item name="windowEnterAnimation">#anim/dialog_enter</item>
<item name="windowExitAnimation">#anim/dialog_exit</item>
</style>
You set windowEnterAnimation to the animation resource to run when the window is being shown, and windowExitAnimation to the one to run when it is hidden. If not set, no animation is run.
So for your code here, you can just make a Dialog, set its content to your custom content, set its gravity, width and height to the values you have here, and set its windowAnimations field to your style defining the animations. You can also tweak the flags if you want some behavior different than a default dialog (not touch modal or such). The API on Dialog.getWindow() has everything you need to set the layout params.
mParams.windowAnimations = android.R.style.Animation_Toast;
mParams.windowAnimations = android.R.style.Animation_Toast;
Where android.R.style.Animation_Toast is a style resource defining the animations to use for this window. This must be a system resource, it can not be an application resource because the window manager does not have access to applications.
Others valid styles are:
mParams.windowAnimations = android.R.style.Animation_Translucent;
mParams.windowAnimations = android.R.style.Animation_Dialog;