The question is how you can bypass your phone’s WiFi and connect your phone to the Internet via your PC, that is using the USB cable.

It is possible, and it is called reverse Tethering, as opposed to using your phone’s WiFi internet to obtain internet connection for you PC (which is then called normal tethering).

This instruction should work for any phone with Android operating system, but specifically I managed to do it for my Xiaomi Redmi 4X phone.

The reason why this was important in my case is the fact that their official MiPCSuite, which should be used for connecting to the Internet among other things, wouldn’t work with their new Redmi Phones and with my Redmi 4X as well. Their last update is dated 03.07.2015. That means that all newer phones with newer operating systems won’t be able to use Mi PC Suite.

So here we go:

  1. If you haven’t done so, you have to switch on USB debugging. Navigate to Settings —> About Home. Find MIUI version field. Touch it 7 times in a row. This will enable Developer Options.
  2. Go to Settings —> Additional Settings —> Developer Options —> USB debugging and enable it.
  3. Install Reverse Tethering Server from this page by downloading the Windows Zip file. (Note that your computer should have at least Java Runtime Environment 1.7 installed, which on my Windows 7 was already there.) In fact, when you download the Server, there is nothing to install, just unzip the file and start the exe file called in the current version ReverseTetheringServer_1.1.2.exe. When you start the server nothing will happen, no visual confirmation, except the fact that the server is active and will accept connections from your phone.
  4. On your phone, install the ReverseTethering NoRoot app. One usually uses Google Play to do that.
  5. Plug your phone with the USB cable. Start the app and connect to the server.
  6. That’s it. You can now use the newly established internet connection.

If you want to change the color of a Drawable Shape in Android Studio Dynamically, this is a short tutorial that will help you do that.

  1. Create a New Project
  2. Name it however you want and choose an appropriate directory:
  3. Chose the target Android Device. I chose Android 4.03, IceCreamSandwich:
  4. Let it be an Empty Activity Based Project
  5. First we will create the shape. In order to do that, expand the “app” folder, then go to the “res”  and right click on the “drawable”. Select New->Drawable resource file, like in the screen capture bellow.
  6. Name the resource file. I choose “myshape” and click OK.
  7. Go to the newly created myshape.xml file. We are going to edit it because we want to make a new shape we will be using in our project. The file looks like this:Modify the code of this file like this:
    <?xml version="1.0" encoding="utf-8"?>
    <shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    
        <stroke android:width="5pt" android:color="@android:color/holo_blue_dark" />
        <solid android:color="#333" />
    
    </shape>

    What this code does is effectively creates a rectangle with a solid color having a stroke of 5pt of holo blue color.

  8. Once we have our myshape.xml code in place, it’s time to work on the activity_main.xml. By default, if you are using the latest Android Studio version, which is 2.3 as of writing this post, you will have the Constraint Layout already set up for you.
    What we want to do for this example is add one EditText field, and 2 Buttons. With the EditText we are going to set its background  as our shape – myshape. The 2 buttons are going to serve to change the color of the background at runtime. Here’s the code of activity_main.xml.:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="me.butka.but.drawablecolor.MainActivity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    
        <EditText
            android:id="@+id/edit"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:background="@drawable/myshape"
            tools:layout_editor_absoluteY="0dp"
            tools:layout_editor_absoluteX="8dp" />
        <Button
            android:id="@+id/blue_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Blue"
            app:layout_constraintTop_toBottomOf="@+id/edit"
    
            tools:layout_editor_absoluteX="0dp" />
        <Button
            android:id="@+id/red_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Red"
            app:layout_constraintTop_toBottomOf="@+id/blue_button"
            tools:layout_editor_absoluteX="0dp" />
    </android.support.constraint.ConstraintLayout>
  9. Next we go to the third file we have to change: MainActivity.java. Here’s the entire code:
    package me.butka.but.drawablecolor;
    
    import android.graphics.Color;
    import android.graphics.drawable.GradientDrawable;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    
    public class MainActivity extends AppCompatActivity {
    
        private EditText edit;
        private Button blue_button;
        private Button red_button;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            edit = (EditText) findViewById(R.id.edit);
            blue_button  = (Button) findViewById(R.id.blue_button);
            red_button  = (Button) findViewById(R.id.red_button);
    
            blue_button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GradientDrawable gradientDrawable = (GradientDrawable) edit.getBackground().mutate();
                    gradientDrawable.setColor(Color.BLUE);
                }
            });
    
            red_button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GradientDrawable gradientDrawable = (GradientDrawable) edit.getBackground().mutate();
                    gradientDrawable.setColor(Color.RED);
                }
            });
    
        }
    }

    What we have here is we have defined 2 OnClickListeners for the 2 buttons we defined earlier that set the color of the EditText field to Blue or Red.

  10. That’s it. Now we can hit “Run” and test the code in some of the available Virtual Devices, like this.
  11. It should look something like this, depending on your Virtual Device:

Hope you like this, and thanks for following.

References: Based on this video tutorial.