Я разработал страницу, состоящую из панели инструментов с tablayout и viewpager. на этих страницах используется стиль Theme.AppCompat.Light.NoActionBar как тема приложения amin. Все работает нормально, я могу просматривать страницы слайдов страниц, кроме того, что я не могу просмотреть имена вкладок в tablayout. Пожалуйста, любой один помочь мне, я использую Android Studio 2.2.1Невозможно просмотреть имена вкладок в макете вкладок с помощью viewpager в студии android
Xml дизайн код страницы является:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_gravity="end"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
style="@style/CustomTabLayoutStyle"/>
<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"
/>
</LinearLayout>
<RelativeLayout
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#CC194740"
android:orientation="vertical" >
<LinearLayout
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:gravity="center_vertical"
android:background="#328e80"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
/>
<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#fff"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<ListView android:id="@+id/drawer_list"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_marginTop="70dp"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Java-код этой конструкции XML является
package info.sants_thapal;
import android.support.v7.widget.Toolbar;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.design.widget.TabLayout.TabLayoutOnPageChangeListener;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.FragmentTabHost;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.squareup.picasso.Picasso;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import info.sants_thapal.CustomGridViewAdapter.ViewHolder;
import static android.provider.Settings.System.AIRPLANE_MODE_ON;
public class Social extends AppCompatActivity implements OnItemSelectedListener {
private static final String TAB_5_TAG = null;
// Tab titles
private String[] tabs = {"Life", "Friends", "Groups"};
SharedPreferences sPref;
Button login;
String session_email = "", session_type = "", session_st, session_ph, session_loc;
//TabHost tabHost1;
ArrayList<HashMap<String, Object>> usersList, usersList1;
int imageId;
ImageView imageView;
TextView text, tv, tv2, tv3;
DrawerLayout mDrawerLayout;
String namess, counta;
// ListView represents Navigation Drawer
ListView mDrawerList, mDrawerList1;
private RelativeLayout mDrawerRelativeLayout;
// ActionBarDrawerToggle indicates the presence of Navigation Drawer in the action bar
ActionBarDrawerToggle mDrawerToggle;
Handler mHandler;
Runnable refresh;
Context mcontext;
String o, n, afsa;
int abd2;
private Button mSubmit;
RelativeLayout notifCount, notifCount2, notifCount3;
private PopupWindow pwindo;
MenuItem item, item2, item3;
ViewHolder viewholder;
List<HashMap<String, String>> aList;
public String[] namesaram, countrycodes;
private TypedArray imgs;
// Title of the action bar
String mTitle = "";
static String IP = IpAddress.Ip;
private String PRE_IMAGE2 = IP + "/images/procover/";
private static String url_all_properties = IP + "/social/pic2.php";
private static String url_all_properties3 = IP + "/social/coun.php";
private static String url_all_properties5 = IP + "/social/coun2.php";
//private static String url_all_properties6 = IP+"/social/coun6.php";
private static String url_all_properties303 = IP + "/social/logou.php";
private static String url_all_properties99 = IP + "/social/spanfspinpost.php";
private static String url_all_properties2 = IP + "/social/spanfspinpost2.php";
private static String url_all_properties999 = IP + "/social/spanfspinpost3.php";
private static String url_create_product = IP + "/social/save.php";
private static final String TAG_SUCCESS = "success";
//private static final String TAG_SUCCESS1 = "mass";
private static final String TAG_USER = "users";
JSONParser jParser = new JSONParser();
//private String PRE_IMAGE = IP+"/upload/";
private static final String TAG_PRO = "propertiesgfdfgd";
private static final String TAG_PRO2 = "properties";
private static final String LOG_TAG = null;
protected static final int NUM_THREADS = 0;
//private static final String TAG_PRO1 = "properties1";
// products JSONArray
JSONArray users = null;
//JSONArray users1 = null;
JSONParser jsonParser = new JSONParser();
int abu, abd;
private FragmentTabHost mTabHost;
View layout;
TabLayout tabLayout;
ViewPager viewPager;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
/*public class ViewHolder
{
TextView tv,tv2;
}*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.social);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
sPref = this.getSharedPreferences("REAL", Context.MODE_PRIVATE);
// intent=getIntent();
session_email = sPref.getString("SESSION_UID", "");
session_ph = sPref.getString("SESSION_PH", "");
session_type = sPref.getString("SESSION_TYPE", "");
session_st = sPref.getString("SESSION_STAT", "");
session_loc = sPref.getString("SESSION_LOC", "");
//private String[] tabs = {"Life", "Friends", "Groups"};
tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("Life"));
tabLayout.addTab(tabLayout.newTab().setText("Friends"));
tabLayout.addTab(tabLayout.newTab().setText("Groups"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
viewPager = (ViewPager) findViewById(R.id.pager);
TabsPagerAdapter mAdapter = new TabsPagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(mAdapter);
viewPager.addOnPageChangeListener(new TabLayoutOnPageChangeListener(tabLayout));
tabLayout.post(new Runnable() {
@Override
public void run() {
tabLayout.setupWithViewPager(viewPager);
}
});
//tabLayout.setupWithViewPager(viewPager);
tabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
}
Код другого класса для вызова вкладок TabsPagerAdapter.java
package info.sants_thapal;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class TabsPagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
public TabsPagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}
@Override
public Fragment getItem(int index) {
switch (index) {
case 0:
// Top Rated fragment activity
TabFragment1 tab1 = new TabFragment1();
return tab1;
case 1:
// Games fragment activity
TabFragment2 tab2 = new TabFragment2();
return tab2;
case 2:
// Movies fragment activity
TabFragment3 tab3 = new TabFragment3();
return tab3;
default:
return null;
}
}
@Override
public int getCount() {
// get item count - equal to number of tabs
return mNumOfTabs;
}
public void clear() {
// TODO Auto-generated method stub
}
}
Построить .grade файл minsdkversion 21 целевой SDK версии 22
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
okay Позвольте мне проверить .. спасибо за ответ –
Бро спасибо за помощь ... это сработало –
удовольствие услышать это! .and Пожалуйста, отметьте этот ответ как полезный, чтобы закончить темы @ AnishYesudasan –