Skip to content

Instantly share code, notes, and snippets.

@YvesBill
YvesBill / style.xml
Created March 8, 2017 09:59
Style for TabLayout
<style name="TabLayout" parent="Widget.Design.TabLayout">
<item name="tabTextAppearance">@style/MyCustomTabText</item>
<item name="tabSelectedTextColor">#fff</item>
</style>
<style name="MyCustomTabText" parent="TextAppearance.AppCompat.Button">
<item name="android:textSize">14sp</item>
<item name="android:textColor">@android:color/darker_gray</item>
</style>
@YvesBill
YvesBill / your_layout.xml
Created March 8, 2017 09:57
Layout for ViewPager+TabLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#fafafa"
android:id="@+id/coordinatorLayout">
<RelativeLayout
android:layout_width="match_parent"
@YvesBill
YvesBill / myTabFrame.java
Created March 8, 2017 09:54
A Fragment which has 3 Tabs within a ViewPager
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; //Ogni classe deve appartenere al support.v4
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
case 0:
//Close Drawer
mDrawerList.setItemChecked(position, true);
setTitle(mStringTitles[position]);
mDrawerLayout.closeDrawer(mDrawerView);
//Wait 270 milliseconds for change fragment view
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Gli importi delle classi
import com.google.ads.AdRequest;
import com.google.ads.AdView;
// Va implementato appena sotto il metodo onCreate
AdView adview = (AdView)findViewById(R.id.adView);
AdRequest re = new AdRequest();
adview.loadAd(re);
<!-- Gli xmlns obbligatori da utilizzare nel layout sono i seguenti
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" -->
<!-- Questo è il banner -->
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.google.ads.AdView">
<attr name="backgroundColor" format="color" />
<attr name="primaryTextColor" format="color" />
<attr name="secondaryTextColor" format="color" />
<attr name="keywords" format="string" />
<attr name="refreshInterval" format="integer" />
</declare-styleable>
</resources>
<!-- aggiungere questi meta-data -->
<meta-data android:name="Nome del banner"
android:value="ID del banner"></meta-data>
<meta-data android:name="ADMOB_ALLOW_LOCATION_FOR_ADS"
android:value="false"></meta-data>
<!-- aggiungere questi permessi -->
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
AppSectionsPagerAdapter mAppSectionsPagerAdapter;
ViewPager mViewPager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Settare il tipo di navigazione
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />