How to link material buttons desing to social networks?

1

My problem is as follows, create a menu with Material desing and I do not know how to link the url of my profiles to the buttons that are displayed

BELOW I LEAVE MY CODE

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="co.com.canalcnc.menumaterial.MainActivity">

<com.getbase.floatingactionbutton.FloatingActionsMenu
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/multiple_actions"
    android:layout_margin="16dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    app:fab_addButtonColorNormal="#0085c3"
    app:fab_addButtonColorPressed="#00FF04"
    tools:ignore="ExtraText">

    <com.getbase.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/action_a"
        app:fab_icon="@drawable/facebook"


        />
    <com.getbase.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/action_b"
        app:fab_icon="@drawable/instagram"
        />
    <com.getbase.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/action_c"
        app:fab_icon="@drawable/twitter"
        />



        </com.getbase.floatingactionbutton.FloatingActionsMenu>

        </RelativeLayout>

Here I leave an example assuming that I believe a button similarly, the code is relatively simple but what you have to do to link it is to use your mainactivity to link it because this can not be done only with xml.

 public class MainActivity extends AppCompatActivity implements 

View.OnClickListener {

 private Button btn;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 btn=(Button)findViewById(R.id.boton_navegacion);
 btn.setOnClickListener(this);
 }

 @Override
 public void onClick(View v) {
 Uri uriUrl = Uri.parse("http://www.facebook.com/");
 Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
 startActivity(intent);
   }
  }

Now here is the button with xml.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 tools:context=".MainActivity">

 <Button
  android:id="@+id/boton_navegacion"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  android:layout_marginTop="30dp"
  android:text="Navegar" />
  </LinearLayout>

If you notice in the code the only thing that happens is that you send to call your xml button from your MainActivity using the ID and the only thing you have to do is put the click event so that when this happens I will send you to the link that you would put inside as I show you in the code.

    
asked by Victor David Chavez Moralez 14.03.2018 в 20:56
source

1 answer

1

I apologize, I did not notice that it was a FloatingActionButton , again here I leave an example assuming that I create a FloatingActionButton in the same way, the code is relatively simple but what you have to do to Linking it is using your mainactivity to link it since this can not be done with xml only.

<com.github.clans.fab.FloatingActionMenu
  <com.github.clans.fab.FloatingActionButton
        android:id="@+id/floating_facebook"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/action_fb"
        fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>

Now the way you will put the link will be as follows. All this has to go inside your MainActivity.

FloatingActionMenu materialDesignFAM;
FloatingActionButton1;

materialDesignFAM = (FloatingActionMenu) findViewById(R.id.social_floating_menu);
floatingActionButton1 = (FloatingActionButton) findViewById(R.id.floating_facebook);

floatingActionButton1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent facebookIntent = getOpenFacebookIntent(MainActivity.this);
            startActivity(facebookIntent);

        }
    });

URL method.

public static Intent getOpenFacebookIntent(Context context) {

    try {
        context.getPackageManager()
                .getPackageInfo("com.facebook.katana", 0); //Intenta abrir FB APP
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("fb://page/376227335860239"));
    } catch (Exception e) {
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://www.facebook.com/karthikofficialpage")); //Abre la pagina de facebook en una pagina nueva (Navegador). 
    }
}

If you notice in the code the only thing that happens is that you send to call your xml button from your MainActivity using the ID and the only thing you have to do is put the click event so that when this happens I will send you to the link that you would put inside as I show you in the code.

Add this code to all the respective buttons.

    
answered by 14.03.2018 в 21:24