如何在右端增加溢出菜单中的选项卡在Android手机 [英] How to add Overflow menu at right end in Tabs in Android Phone
本文介绍了如何在右端增加溢出菜单中的选项卡在Android手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提出一个Android应用程序,我需要创建两个标签
这是我做简单,但我还需要添加溢出菜单中相同的行。见截图。
I am making an android application where I need to create two Tabs
that is simple I did but I need to add the OverFlow menu also in same row. See screenshot.
我从来没有在Android的可能似乎更棘手我实现这一点。
I never implement this in Android that might seems more tricky to me.
请帮助我,如果你知道如何在Android中实现这一点。
Please help me if you know how to achieve this in Android.
我简单地实现了标签
使用低于code。
I simply achieved the Tabs
using below code.
public class PayStubActivity extends ActionBarActivity implements ActionBar.TabListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // requesting to set the custom title bar
setContentView(R.layout.activity_pay_stub);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
// adding action bar tabs to the activity
ActionBar mActionBar = getSupportActionBar();
Tab firstTab = mActionBar.newTab().setText(getString(R.string.paystub_current_tab)).setTabListener(this);
Tab secondTab = mActionBar.newTab().setText(getString(R.string.paystub_all_tab)).setTabListener(this);
// add the tabs to the action bar
mActionBar.addTab(firstTab);
mActionBar.addTab(secondTab);
// set the navigation mode the Action Bar Tabs
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) {
// user is selected first tab
if(tab.getPosition() == 0) {
fragmentTransaction.replace(R.id.container, new CurrentPayStubFragment());
} else {
// user is selected second tab.
}
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction fragmentTransaction) {}
}
先谢谢了。
推荐答案
您将需要自定义布局你的动作条:
You will need a custom Layout for your Action bar:
layout_action_bar:
layout_action_bar:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:showDividers="middle"
android:divider="@drawable/action_bar_divider"
android:dividerPadding="10dp"
android:weightSum="7">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:clickable="true"
android:onClick="imagesViewClick">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="IMAGES"
android:textColor="@android:color/white"
android:gravity="center"
android:layout_centerInParent="true"/>
<View
android:id="@+id/images_selected_view"
android:layout_width="match_parent"
android:layout_height="6dp"
android:layout_alignParentBottom="true"
android:background="#427fed"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:clickable="true"
android:onClick="videosViewClick">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="VIDEOS"
android:textColor="@android:color/white"
android:gravity="center"
android:layout_centerInParent="true"/>
<View
android:id="@+id/videos_selected_view"
android:layout_width="match_parent"
android:layout_height="6dp"
android:layout_alignParentBottom="true"
android:background="#427fed"
android:visibility="gone"/>
</RelativeLayout>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_overflow"
android:layout_gravity="center_vertical"
android:layout_weight="1"/>
</LinearLayout>
和那么你的活动实施:
public class MainActivity extends ActionBarActivity{
private View imagesViewSelected;
private View videosViewSelected;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new ImagesFragment())
.commit();
}
}
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
ActionBar.LayoutParams lp1 = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
View customNav = LayoutInflater.from(this).inflate(R.layout.layout_action_bar, null);
imagesViewSelected = customNav.findViewById(R.id.images_selected_view);
videosViewSelected = customNav.findViewById(R.id.videos_selected_view);
actionBar.setCustomView(customNav, lp1);
}
public static class ImagesFragment extends Fragment {
public ImagesFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
((TextView)rootView.findViewById(R.id.txt_fragment_locator)).setText("Images Fragment");
return rootView;
}
}
public static class VideosFragment extends Fragment {
public VideosFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
((TextView)rootView.findViewById(R.id.txt_fragment_locator)).setText("Videos Fragment");
return rootView;
}
}
public void imagesViewClick(View view){
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new ImagesFragment())
.commit();
imagesViewSelected.setVisibility(View.VISIBLE);
videosViewSelected.setVisibility(View.GONE);
}
public void videosViewClick(View view){
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new VideosFragment())
.commit();
imagesViewSelected.setVisibility(View.GONE);
videosViewSelected.setVisibility(View.VISIBLE);
}
}
这篇关于如何在右端增加溢出菜单中的选项卡在Android手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文