Posts

Showing posts with the label Android

Android Material Design Button Styles

Image
Answer : I will add my answer since I don't use any of the other answers provided. With the Support Library v7, all the styles are actually already defined and ready to use, for the standard buttons, all of these styles are available: style="@style/Widget.AppCompat.Button" style="@style/Widget.AppCompat.Button.Colored" style="@style/Widget.AppCompat.Button.Borderless" style="@style/Widget.AppCompat.Button.Borderless.Colored" Widget.AppCompat.Button : Widget.AppCompat.Button.Colored : Widget.AppCompat.Button.Borderless Widget.AppCompat.Button.Borderless.Colored : To answer the question, the style to use is therefore <Button style="@style/Widget.AppCompat.Button.Colored" ....... ....... ....... android:text="Button"/> How to change the color For the whole app: The color of all the UI controls (not only buttons, but also floating action buttons, checkboxes etc.) is managed by the attribute ...

Android WebView Style Background-color:transparent Ignored On Android 2.2

Image
Answer : This worked for me, mWebView.setBackgroundColor(Color.TRANSPARENT); At the bottom of this earlier mentioned issue there is an solution. It's a combination of 2 solutions. webView.setBackgroundColor(Color.TRANSPARENT); webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); When adding this code to the WebViewer after loading the url, it works (API 11+). It even works when hardeware acceleration is ON I had the same issue with 2.2 and also in 2.3. I solved the problem by giving the alpa value in html not in android. I tried many things and what I found out is setBackgroundColor(); color doesnt work with alpha value. webView.setBackgroundColor(Color.argb(128, 0, 0, 0)); will not work. so here is my solution, worked for me. String webData = StringHelper.addSlashes("<!DOCTYPE html><head> <meta http-equiv=\"Content-Type\" " + "content=\"text/html; charset=utf-8\"> </head><body><di...

Cordova Run (in Real) Android Device Using Command Line?

Answer : You can force the run on device like this cordova run android --device If you get an error message like "No devices found" then make sure that you have developer mode and USB Debugging enabled on the device and also run adb kill-server and then adb devices should list your device and cordova run android --device should work For iOS you can run from macOS cordova run ios --device If it doesn't work, make sure you have ios-sim and ios-deploy installed and that you have your development certificate and a wildcard provisioning profile on your machine. You can open the .xcworkspace file on /platforms/ios/ and Xcode will help you to create the certificates and provisioning profiles when you try to run the app. If a real device is connected to your pc and it is recognized as well, you ca just use cordova run android and the app will start on your device. It worked for me.

ADB Over Wireless

Answer : Rooting is not required. With USB cable connected, port 5555 opened across all involved firewalls and debug mode enabled adb tcpip 5555 then look into wireless properties of your device and the network you use, to see which IP address have been granted to device (or configure your DHCP always to use the same for the device mac address). Then adb connect 192.168.1.133 (were 192.168.1.133 is a sample IP address). This is all. You can now use adb shell or adb install or adb upload or the like with USB cable plugged out. To switch back to USB mode, adb usb The device may also revert back to USB mode after reboot. This mode is needed for development of applications that use attached USB devices directly (USB port is used by device so cannot be used by ADB). It is briefly covered in the USB debugging section of the Android website. I ran into the same problem today and find that things are fine on my non-rooted 4.2 Galaxy Nexus device, but does not work on m...

Android Canvas Clear With Transparency

Answer : Use the following. canvas.drawColor(Color.TRANSPARENT,Mode.CLEAR); The solution was to create a secondary canvas and bitmap to draw on. My Custom View's onSizeChanged() method looked like @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); bitmap.eraseColor(Color.TRANSPARENT); temp = new Canvas(bitmap); } and the onDrawMethod looks like @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); temp.drawColor(Color.argb(80, 0, 0, 0)); temp.drawCircle(centerPosX, centerPosY, 200, transparentPaint); canvas.drawBitmap(bitmap, 0, 0, null); } where transparentPaint is declared in the onstructor as transparentPaint = new Paint(); transparentPaint.setColor(getResources().getColor(android.R.color.transparent)); transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode....

Android Pick Images From Gallery

Answer : Absolutely. Try this: Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE); Don't forget also to create the constant PICK_IMAGE , so you can recognize when the user comes back from the image gallery Activity: public static final int PICK_IMAGE = 1; @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PICK_IMAGE) { //TODO: action } } That's how I call the image gallery. Put it in and see if it works for you. EDIT: This brings up the Documents app. To allow the user to also use any gallery apps they might have installed: Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); getIntent.setType("image/*"); Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT...

Android Emulator Error: "System UI Has Stopped"

Answer : This is still "unanswered", but it probably has been resolved. I just want to share my experience and clarify a few things, some of which may not matter. Anyway, if this helps someone else that's great. 1) I had this problem on one machine (a new, but slower machine), but not another (the faster one) when running a 4.0.3 emulator. It is not a hardware problem though, and CPU speed doesn't make a difference. 2) Both machines are fully up-to-date ADT (Eclipse 4.2.x and Android 4.2.2 (API 17) SDK environments. 3) Editing, or even Deleting the emulator and then recreating it did NOT fix it. 4) The best solution is to locate and update the config.ini file. In Windows 7 (x64) I found the config.ini file in C:\Users \ [your user name] \ .android\avd\ICS_4.0.3_API_15.avd [*see AVD names below]. NOTE: First make sure you have “show hidden files, folder, or drives” turned on in Explorer or you won't see the ".android" folder. 5) Not s...

Android Studio 3.1.1 CreateProcess Error=206, The Filename Or Extension Is Too Long

Answer : I guess you are the windows user, there is a file path limit of 8191 in Windows XP and above. http://support.microsoft.com/kb/830473/en-us The simplest way this shorten the file path, like change the project folder into D:\, and refact your project path, and always use ASCII chars for the folder name. UTF-8 chars use 2-3 bytes. or move useless dependency. or change to MAC platform. ;) The reason is at the compile step, there is a command like javac xxxx, combine all dependences's path in one line. For me this worked. Go to Build -> Clean. File -> Invalidate Cache and Restart Or It might be due to network issue. Please check connectivity.

Android - How To Disable STATE_HALF_EXPANDED State Of A Bottom Sheet

Image
Answer : The value of the half expanded ratio must be set to some value between 0 and 1 exclusive , so set this value to some very low number that is certain to be less than your peek height, say "0.0001f". With this value you should not even see the STATE_HALF_EXPANDED state. The states will fluctuate between STATE_EXPANDED and STATE_COLLAPSED . Alternate solution The solution above works and effectively disables the STATE_HALF_EXPANDED state, but it is hackish (IMO) and may break in the future. For instance, what if a reasonable value for the half expanded ratio which is somewhere between the peek height and the full height is enforced? That would be trouble. The requirements as stated by the OP is that the bottom sheet should transition between the peek height and the full height. There is no problem with the peek height, but the OP specifies isFitToContents = false to get to the full height. (I assume that his bottom sheet may be shorter then the available...

Android: How Does Bitmap Recycle() Work?

Answer : The first bitmap is not garbage collected when you decode the second one. Garbage Collector will do it later whenever it decides. If you want to free memory ASAP you should call recycle() just before decoding the second bitmap. If you want to load really big image you should resample it. Here's an example: Strange out of memory issue while loading an image to a Bitmap object. I think the problem is this: On pre-Honeycomb versions of Android, the actual raw bitmap data is not stored in VM memory but in native memory instead. This native memory is freed when the corresponding java Bitmap object is GC'd. However , when you run out of native memory, the dalvik GC isn't triggered, so it is possible that your app uses very little of the java memory, so the dalvik GC is never invoked, yet it uses tons of native memory for bitmaps which eventually causes an OOM error. At least that's my guess. Thankfully in Honeycomb and later, all bitmap data is stored in...

Bypass With Wrong Cvv Of Debit Card And Getting OTP

Answer : But shouldn't it suppose verify before I get the OTP? What's the reason, Isn' it a security issue? This is absolutely NOT a security issue! quite the opposite it's a protection. Lets go through the steps. You put in card details. You put in CVV You put in the OTP. The payment is processed if and only if the combination of all of it are correct. Now assume a scenario where it tell's you the CVV is wrong before the 2FA that is just going to simply give the attacker a chance to better attack.Now the attacker knows the CVV is wrong and can simply change that.While in the correct scenario attacker will have to break 2 Factor authentication to gain that information As well as the general rule of not giving the attacker information by rejecting too early, there are some things specific to the payment industry which are somewhat relevant. Although often presented to the customer as mandatory, the authentication information on a payment i...

Android : Control Smooth Scroll Over Recycler View

Answer : It's unclear what you mean when you say " smoothScroll ". You could be referring to the automatic " smoothScrollToPosition " which will automatically scroll to a specified position, you could be talking about manual scrolling and you could be talking about flinging. For the sake of prosperity, I will attempt to answer all of these issues now. 1. Automatic smooth scrolling. Inside your layout manager, you need to implement the smoothScrollToPosition method: @Override public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) { // A good idea would be to create this instance in some initialization method, and just set the target position in this method. LinearSmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) { @Override public PointF computeScrollVectorForPosition(int targetPosition) { int yDelta = calculateC...

Android: GetContext().getContentResolver() Sometimes Gets NullPointerException

Answer : If you look in the source of ContentProvider (just hold SHIFT and click on the classname in Android Studio) then you will find that the implementation is holding an object of type Context as mContext. Your solution is just the same, which means if mContext of ContentProvider is null, your reference will also be null. So there is no need for this. To help you out, this is just a warning of your IDE if make such a construct yourself. But in this case there will always be context, because the ContentProvider is generated by your system. To avoid the error in your IDE just write @SuppressWarnings("ConstantConditions") above your class definition like: ... @SuppressWarnings("ConstantConditions") public class NoteProvider extends ContentProvider { ... If you can make sure that getContext() can never be null then you can simply ignore this warning. I think the warning even disappears of you just check for null: if (getContext() != null) { getCon...

Android: Statically Underline Dynamic Text In TextView

Answer : The easiest solution is probably to create a custom UnderLineTextView component deriving from TextView, override setText() and set the entire text as underlined, something like this (underline code from the link you referred to above): @Override public void setText(CharSequence text, BufferType type) { // code to check text for null omitted SpannableString content = new SpannableString(text); content.setSpan(new UnderlineSpan(), 0, text.length(), 0); super.setText(content, BufferType.SPANNABLE); } It's then just a matter of using your new component in the layout and setting the text as usual. The rest is handled automatically. More info on custom components: http://developer.android.com/guide/topics/ui/custom-components.html You can underline text over Html.fromHtml(String source) Example: textView.setText(Html.fromHtml("this is <u>underlined</u> text"));

Android How Do I Correctly Get The Value From A Switch?

Answer : Switch s = (Switch) findViewById(R.id.SwitchID); if (s != null) { s.setOnCheckedChangeListener(this); } /* ... */ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Toast.makeText(this, "The Switch is " + (isChecked ? "on" : "off"), Toast.LENGTH_SHORT).show(); if(isChecked) { //do stuff when Switch is ON } else { //do stuff when Switch if OFF } } Hint: isChecked is the new switch value [ true or false ] not the old one. Since it extends from CompoundButton (docs), you can use setOnCheckedChangeListener() to listen for changes; use isChecked() to get the current state of the button. Switch switch = (Switch) findViewById(R.id.Switch2); switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { ...

Adb Kill-server Not Responding?

Answer : I also came across the same error when I was trying to install one app in emulator. You need not restart PC to overcome this. Just kill the server. if 'adb kill-server' is also not working, kill the process (adb.exe) through task manager. There you go!! Task Manager -> Process -> adb.exe -> End process That worked for me. If zombie adb process is not the issue i.e. there's no adb.exe in the task-manager list, the problem is usually adb ports e.g. 5555, 5554, 5037 etc., being taken by other applications. Solutions: On all Windows : find the process taking one of those ports using netstat -bn and kill it from task-manager Ctrl+Shift+Esc is the shortcut. On Windows 7 and 8 : there's this new tool called Resource Monitor . It'll also allow you to find out the blocked port and blocking process under the network tab. On Linux : the similar is done with netstat -pn . Feel free to use your grep foo as needed and kill the blocking pr...

Android Studio - Keystore Was Tampered With, Or Password Was Incorrect

Answer : I had a similar problem while updating my app. The keytool was not reading the correct keystore file and instead pointing to an older keystore file that I created months ago and not used. Searched for some solutions online but didn't find one. Almost gave up but I thought about cleaning the project by clicking Build then Clean Project . This last resort worked for me. Apparently I just found another post posted few months ago that solved my issues I struggled for days... Simply need to change the keystore and key alias password to be the same for it to work. Though I still don't know why the same keystore worked before when I was publishing updates; then not working anymore until I changed the passwords. If anyone has answer for that, please let everyone know! Apparently Google decided to set the default keystore password to be android . The keytool utility prompts you to enter a password for the keystore. The default password for the debug keystore is ...

Android - How To Filter Emoji (emoticons) From A String?

Answer : Emojis can be found in the following ranges ( source ) : U+2190 to U+21FF U+2600 to U+26FF U+2700 to U+27BF U+3000 to U+303F U+1F300 to U+1F64F U+1F680 to U+1F6FF You can use this line in your script to filter them all at once: text.replace("/[\u2190-\u21FF]|[\u2600-\u26FF]|[\u2700-\u27BF]|[\u3000-\u303F]|[\u1F300-\u1F64F]|[\u1F680-\u1F6FF]/g", ""); Latest emoji data can be found here: http://unicode.org/Public/emoji/ There is a folder named with emoji version. As app developers a good idea is to use latest version available. When You look inside a folder, You'll see text files in it. You should check emoji-data.txt. It contains all standard emoji codes. There are a lot of small symbol code ranges for emoji. Best support will be to check all these in Your app. Some people ask why there are 5 digit codes when we can only specify 4 after \u. Well these are codes made from surrogate pairs. Usually 2 symbols are used to encode one...

Android Studio Rendering Problems

Image
Answer : Change your android version on your designer preview into your current version depend on your Manifest. rendering problem caused your designer preview used higher API level than your current android API level. Adjust with your current API Level. If the API level isn't in the list, you'll need to install it via the SDK Manager. In new update android studio 2.2 facing rendering issue then follow this steps. I fixed it - in styles.xml file I changed "Theme.AppCompat.Light.DarkActionBar" to "Base.Theme.AppCompat.Light.DarkActionBar" It's some kind of hack I came across a long time ago to solve similar rendering problems in previous Android Studio versions. Open AndroidManifest.xml Change: android:theme="@style/AppTheme" to something like: android:theme="@style/Theme.AppCompat.Light" Hit "refresh" button in the "Previev" tab.

Android Spinner Dropdown Arrow Not Displaying

Answer : This works for me, much simpler as well: <Spinner android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Light" android:spinnerMode="dropdown" /> And in your class file: spinner = (Spinner) view.findViewById(R.id.spinner); ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.spinner_data, android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); Hope this helps ;) Try this one: <Spinner android:id="@+id/spinnPhoneTypes" android:layout_width="0dp" style="@android:style/Widget.Spinner.DropDown" android:layout_height="@dimen/thirtyFive" android:layout_marginLeft="10dp" android:layout_weight="1...