活动:
public class LoginActivity extends BaseActivity { public static final String selectedTabposition = "selectedTabposition"; //Tab tag name private static String TAB_1_TAG = "Email"; private static String TAB_2_TAG = "Mobile"; private TabLayout mTabLayout; private VIEwPager mVIEwPager; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_login); getwindow().setSoftinputMode(WindowManager.LayoutParams.soFT_input_STATE_ALWAYS_HIDDEN); TAB_1_TAG = getResources().getString(R.string.tab_email); TAB_2_TAG = getResources().getString(R.string.tab_mobile); //Initialise vIEws mVIEwPager = (VIEwPager) findVIEwByID(R.ID.vIEwpager); mTabLayout = (TabLayout) findVIEwByID(R.ID.tabs); //set tab with vIEw pager setupVIEwPager(mVIEwPager); mTabLayout.setupWithVIEwPager(mVIEwPager); setupTabIcons(); mVIEwPager.setonPagechangelistener(new VIEwPager.OnPagechangelistener() { @OverrIDe public voID onPageScrolled(int position,float positionOffset,int positionOffsetPixels) { } @OverrIDe public voID onPageSelected(int position) { dismissKeyboard(mVIEwPager); } @OverrIDe public voID onPageScrollStateChanged(int state) { } }); } /** * Adding custom vIEw to tab */ private voID setupTabIcons() { linearLayout tabOne = (linearLayout) LayoutInflater.from(this).inflate(R.layout.tab_custom,null); TextVIEw tvIconOne = (TextVIEw) tabOne.findVIEwByID(R.ID.tv_tab_Title); tvIconOne.setText(TAB_1_TAG); mTabLayout.getTabAt(0).setCustomVIEw(tabOne); setTypeface(tvIconOne,CustomFonts.Prime_regular); mTabLayout.getTabAt(0).getCustomVIEw().setSelected(true); linearLayout tabTwo = (linearLayout) LayoutInflater.from(this).inflate(R.layout.tab_custom,null); TextVIEw tvIconTwo = (TextVIEw) tabTwo.findVIEwByID(R.ID.tv_tab_Title); tvIconTwo.setText(TAB_2_TAG); setTypeface(tvIconTwo,CustomFonts.Prime_regular); mTabLayout.getTabAt(1).setCustomVIEw(tabTwo); } /** * Adding fragments to VIEwPager * * @param vIEwPager The vIEw pager */ private voID setupVIEwPager(VIEwPager vIEwPager) { VIEwPagerAdapter adapter = new VIEwPagerAdapter(getSupportFragmentManager()); LoginFragment loginFragmentEmail = new LoginFragment(); Bundle emailBundle = new Bundle(); emailBundle.putInt(selectedTabposition,0); loginFragmentEmail.setArguments(emailBundle); LoginFragment loginFragmentMobile = new LoginFragment(); Bundle phoneBundle = new Bundle(); phoneBundle.putInt(selectedTabposition,1); loginFragmentMobile.setArguments(phoneBundle); adapter.addFrag(loginFragmentEmail,TAB_1_TAG); adapter.addFrag(loginFragmentMobile,TAB_2_TAG); vIEwPager.setAdapter(adapter); } class VIEwPagerAdapter extends FragmentPagerAdapter { private final List<Fragment> mFragmentList = new ArrayList<>(); private final List<String> mFragmentTitleList = new ArrayList<>(); public VIEwPagerAdapter(FragmentManager manager) { super(manager); } @OverrIDe public Fragment getItem(int position) { return mFragmentList.get(position); } @OverrIDe public int getCount() { return mFragmentList.size(); } public voID addFrag(Fragment fragment,String Title) { mFragmentList.add(fragment); mFragmentTitleList.add(Title); } @OverrIDe public CharSequence getPageTitle(int position) { return mFragmentTitleList.get(position); } }}
分段:
public class LoginFragment extends BaseFragment { @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { super.onCreateVIEw(inflater,container,savedInstanceState); VIEw rootVIEw = inflater.inflate(R.layout.fragment_login,false); return rootVIEw;}
activity_login.xml:
<?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" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:background="@androID:color/white" androID:orIEntation="vertical"> <ImageVIEw androID:ID="@+ID/iv_Title" androID:layout_wIDth="200dp" androID:layout_height="45dp" androID:layout_centerHorizontal="true" androID:layout_margintop="30dp" /> <androID.support.design.Widget.TabLayout androID:ID="@+ID/tabs" androID:layout_wIDth="match_parent" androID:layout_height="@dimen/custom_tab_layout_height" androID:layout_below="@+ID/iv_Title" androID:layout_margintop="@dimen/spacing_10" app:tabGravity="fill" app:tabIndicatorcolor="@color/app_color_dark" app:tabMode="fixed"/> <VIEw androID:ID="@+ID/vIEw" androID:layout_wIDth="match_parent" androID:layout_height="@dimen/divIDer_height_small" androID:layout_below="@+ID/tabs" androID:background="@color/gray_medium"/> <com.helper.CustomNonSwipeableVIEwpager androID:ID="@+ID/vIEwpager" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_below="@+ID/vIEw" app:layout_behavior="@string/appbar_scrolling_vIEw_behavior"/></relativeLayout>
fragment_login.xml:
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:background="@androID:color/white" androID:orIEntation="vertical"> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margintop="@dimen/spacing_50" androID:orIEntation="vertical"> <EditText androID:ID="@+ID/et_email" androID:layout_wIDth="match_parent" androID:layout_height="@dimen/spacing_48" /> <EditText androID:ID="@+ID/et_password" androID:layout_wIDth="match_parent" androID:layout_height="@dimen/spacing_48" androID:layout_margintop="@dimen/spacing_15"/> </linearLayout></relativeLayout>
AndroIDManifest.xml中:
<activity androID:name=".activitIEs.LoginActivity" androID:screenorIEntation="portrait" />
在AndrodManifest文件中,试过了
androID:windowsoftinputMode = stateHIDden and androID:windowsoftinputMode = adjustPan
CustomNonSwipeableVIEwpager.java:
public class CustomNonSwipeableVIEwpager extends VIEwPager { public CustomNonSwipeableVIEwpager(Context context) { super(context); } public CustomNonSwipeableVIEwpager(Context context,AttributeSet attrs) { super(context,attrs); } @OverrIDe public boolean onIntercepttouchEvent(MotionEvent event) { // Never allow swiPing to switch between pages return false; } @OverrIDe public boolean ontouchEvent(MotionEvent event) { // Never allow swiPing to switch between pages return false; }}
截图:
在转移到FragmentB之前:
在片段B中:
从片段B返回片段A:
解决方法 将requestFocus属性用于第一个editText,这将始终使editText获得焦点.在fragment_login.xml文件中进行以下更改,
<EditText androID:ID="@+ID/et_email" androID:layout_wIDth="match_parent" androID:layout_height="@dimen/spacing_48"> <requestFocus /></EditText>总结
以上是内存溢出为你收集整理的android – 在视图寻呼机中的页面之间移动时,Edittext会自动获得焦点全部内容,希望文章能够帮你解决android – 在视图寻呼机中的页面之间移动时,Edittext会自动获得焦点所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)