I have a customised view, and at certain moment of the game I am developing, I want to show a confirmation message to the user. For the confirmation message, I created a new xml file in the layout folder, and in the cistomised view og the game I am trying to refer to that layout as follows:
private void showConfirmation() {
LayoutInflater mLayoutInf = LayoutInflater.from(this.mContext);
View confMSG_View = mLayoutInf.inflater(R.layout.confirm_msg, null);
.....
.....
}
But, at this step, eclipse underscores the R.Layout.confirm_msg with red and says it can not be resolved to a field.
Please let me know what I am doing wrong here.
Related
I am using the <TimePicker> widget to enable the user to set the time.
However, since I'm embedding the <TimePicker> into one of my views, I'd like to get rid of the TimePicker's header (the crossed out area in the picture).
Default timepicker in Android looks like this:
Question: Is it possible to remove the timepicker's header and use only the analog part of the widget?
There is no public method in TimePicker to directly hide or show the Time Header. Try the below source code will give us the name of the resource ID for that View, which we can get with the system Resources. Then finding the View, and setting its visibility to GONE.(I haven't tested)
private void hideTimeHeaderLayout(TimePicker picker) {
final int id = Resources.getSystem().getIdentifier("time_header", "id", "android");
final View timeLayout = picker.findViewById(id);
if(timeLayout != null) {
timeLayout .setVisibility(View.GONE);
}
}
I don't know how to solve this issue,there are some strings needed to fill in the textview,"#Tony#Tom#James#Brown...",what I want to do is like following "#Tony #Tom #James #Brown..." this will be displayed in the textview,the spacing is also specified,for example,"20dp" is the distance between '#Tony' and '#Tom'.I don't know how to create a textview likes above,I have a another question,when the content is out of range,the content should start from next line,so do I deal with this problem?Thank you anyone who gives an answer. If I didn't discribe this question in detail,forgive me.
You can use https://android-arsenal.com/details/1/2242 .
<com.apradanas.simplelinkabletext.LinkableEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
// find username
Link linkUsername = new Link(Pattern.compile("(#\\w+)"))
.setUnderlined(false)
.setTextColor(Color.parseColor("#D00000"))
.setTextStyle(TextStyle.BOLD)
.setClickListener(new Link.OnClickListener() {
#Override
public void onClick(String text) {
// do something
}
});
more information is available on the android arsenal page
I took the following code to implement my own custom launcher:
https://github.com/fookwood/Launcher3
My goal is it to set an Bitmap or PNG file as an overlay above the normal app icon. But I can´t find the region where google is originally setting the app icon in the "All Apps View". Does somebody know where to look exactly?
Already found it by myself. For everyone who wants to know it. There´s a class called IconCache.Java.
/**
* Fill in "application" with the icon and label for "info."
*/
public synchronized void getTitleAndIcon(AppInfo application, LauncherActivityInfoCompat info,
HashMap<Object, CharSequence> labelCache) {
CacheEntry entry = cacheLocked(application.componentName, info, labelCache,
info.getUser(), false);
application.title = entry.title;
application.iconBitmap = overlay(entry.icon,BitmapFactory.decodeResource(mContext.getResources(), R.drawable.overlay_green));
//application.iconBitmap = entry.icon;
application.contentDescription = entry.contentDescription;
}
Trying to make an Android InputMethod that is transparent - i.e. the underlying content shows through to the keyboard that I am developing.
I've been able to make the View that I pass to the system transparent - I think - but there seems to be something underneath my view that is solid white - and obfuscating the underlying content.
It is definitely possible, these guys do it:
https://play.google.com/store/apps/details?id=com.aitype.android.tablet.p&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5haXR5cGUuYW5kcm9pZC50YWJsZXQucCJd
I figured it out! Not sure if this is how the guys in your play store link did it, but this is what worked for me. Also, I realize this post is over a year old, but I'm still answering it just in case someone else out there discovers this when trying to create a transparent keyboard.
The "something" under your view is actually nothing - it's empty space. Your keyboard pushed the entire view up and out of the way to make room for its height, leaving empty white space behind. Your transparent keyboard let this white space show through.
Here's the solution: instead of returning your view in onCreateInputView, return it in onCreateCandidatesView. That's the view that normally lives above the keyboard and lists the autocorrect suggestions. But you're going to use this to house your actual keyboard.
The reason you want to have your keyboard be a candidates view is because the input view most often pushes the underlying view up. Individual apps can decide how they want to behave when a keyboard is shown via android:windowSoftInputMode and the input view respects their preference, but the candidates view always uses adjustPan.
From the docs: "Note that because the candidate view tends to be shown and hidden a lot, it does not impact the application UI in the same way as the soft input view: it will never cause application windows to resize, only cause them to be panned if needed for the user to see the current focus." http://developer.android.com/reference/android/inputmethodservice/InputMethodService.html
So, return your transparent view from onCreateCandidatesView, return null from onCreateInputView and make sure to call setCandidatesViewShown(true) so your candidates view shows up (I call it in onWindowShown).
Normally InputMethodServices uses background color which is same with current binding application's background color. If you want to make this transparent, I think you should make it as popup-window structure, not an inputmethod window I think.
It may such easy to make the full screen keyboard layout extra area transparent via java reflection only if you're quite familiar with InputMethodService.
the extra area has an id name fullscreenArea, you can fetch the area's id, then findViewById() then set its background.
the keyboard look as this before I done my practice :
a giant blank cover the below page.
so after is :
you can see the below page which contained an EditText and others displayed.
here is my code :
public static void makeKeyboardTransparent(InputMethodService service) {
try {
View decorView = service.getWindow().getWindow().getDecorView();
final int viewId = fetchInternalRId("fullscreenArea");
View fullscreenArea = decorView.findViewById(viewId);
if (fullscreenArea != null) {
modifyView(fullscreenArea);
return;
}
} catch (Exception e) {
}
try {
Class<?> superClass = service.getClass().getSuperclass();
Field fullscreenAreaField = superClass.getDeclaredField("mFullscreenArea");
fullscreenAreaField.setAccessible(true);
View fullscreenArea = (View) fullscreenAreaField.get(service);
if (fullscreenArea != null) {
modifyView(fullscreenArea);
}
} catch (Exception e) {
}
}
private static void modifyView(View fullscreenArea) {
fullscreenArea.setBackgroundColor(Color.TRANSPARENT);
}
private static int fetchInternalRId(String name) throws Exception {
Class<?> rIdClass = Class.forName("com.android.internal.R$id");
return rIdClass.getDeclaredField(name).getInt(rIdClass);
}
I provided two approach to make the blank area transparent, both of them worked fine in my test, all you need is pass your InputMethodService into makeKeyboardTransparent() and see what it can do.
I am writing Instrumentation tests for my android app. One thing I want to do is to find whether all the UI components are on the screen or not. For that I have taken the screen shot of the complete screen and then I am looking for a particular widget in that image.
This code need to be running on the device only, not on desktop.
E.g. the full screen shot (image-1) have various android components like textview, button, listview and a image. Now I have a subset of this image (image-2), suppose the image of the button.
How can I find that whether image-2 is part of image-1?
Assuming that this code is happening from within the application, it doesn't seem like image comparison is the easiest way to determine whether a view is visible.
If you are writing an external instrumentation application of some sort, and this answer doesn't apply, please let me know.
Here's what I would do to test for the presence of UI elements from within the app:
From the Android API docs on the View object: you can find a view by its ID that was set up in the XML file:
<Button
android:id="#+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/my_button_text"/>
In the App:
Button myButton = (Button) findViewById(R.id.my_button);
Then, check the getVisibility() and getGlobalVisibleRect (Rect r, Point globalOffset), both documented on the View doc page.
Pseudocode:
int[] viewIds = {<known ids from xml>};
foreach(int viewId in viewIds) {
View v = findViewById(viewId);
if (v!=null) {
bool isVisible = (v.getVisibility()==VISIBLE) && getGlobalVisibleRect(new Rect(), new Point());
// do something with the visible/invisible info
}
}