如何放置在android系统旁边的一个标签按钮? (相关UI) [英] How to place a button next to a Tab in android ? (Related to UI)
问题描述
我想下一个放置一个按钮,我的标签我的应用程序。我已经给了code以下,以我怎么构建我的标签。
I would like to place a Button next to my Tabs in my app. I've given the code below as to how I am constructing my Tabs.
这是XML
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="330dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<View
android:layout_width="fill_parent"
android:layout_height="0.5dip"
android:background="#000" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dip"
android:layout_marginRight="0dip" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#696969" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#000" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
在code在我的活动:
The code for at my Activity:
public class Secondactivity extends TabActivity {
protected void onCreate(Bundle savedInstanceState) {
setupTabHost();
mTabHost.getTabWidget().setDividerDrawable(se.copernicus.activity.R.drawable.tab_divider);
setupTab(new TextView(this), "Month");
setupTab(new TextView(this), "Week");
setupTab(new TextView(this), "Day");
setupTab(new TextView(this), "Today");
private void setupTab(final View view, final String tag) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
.setContent(new TabContentFactory() {
public View createTabContent(String tag) {
return view;
}
});
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context)
.inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
这是我目前看来,当我跑我的应用程序
This my current view when I run my app
我希望做的是放置一个按钮今天的地方。我如何做呢?
What I would like to do is place a button at the place of today. How can I go about it ?
我已经排除了一些code是XML,将显示pssed状态的问题将得到冗长的$ P $
I've excluded some code that is xml that will show the pressed state as the question would get lengthy
感谢您对您的输入和您的时间。
Thank you for you input and your time.
推荐答案
我用下面的code,产生这一结果。我已经设置了第四个选项卡点击假的。只有选项卡里面的按钮点击。所以它会给出一个IM pression它不是一个标签。希望这会有所帮助。
I have used the following code to generate this result. I have set the fourth tab clickable false. Only the button inside the tab will be clickable. So it would give an impression that it is not a tab. Hope this would help.
活动:
public class MainActivity extends TabActivity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
setupTabHost();
mTabHost.getTabWidget().setDividerDrawable(R.drawable.item_seperator);
setupTab(new TextView(this), "Month");
setupTab(new TextView(this), "Week");
setupTab(new TextView(this), "Day");
final View view = new Button(this);
View tabview = LayoutInflater.from(this).inflate(
R.layout.button_tabs_bg, null);
Button button = (Button) tabview.findViewById(R.id.tabsButton);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Button click",
Toast.LENGTH_SHORT).show();
}
});
TabSpec setContent = mTabHost.newTabSpec("").setIndicator(tabview)
.setContent(new TabContentFactory() {
public View createTabContent(String tag) {
return view;
}
});
mTabHost.addTab(setContent);
mTabHost.getTabWidget().getChildTabViewAt(3).setEnabled(false);
}
private void setupTab(final View view, final String tag) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
.setContent(new TabContentFactory() {
public View createTabContent(String tag) {
return view;
}
});
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context)
.inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
}
tab_bg_selector.xml
<!-- Active tab -->
<item android:state_selected="true" android:state_focused="false"
android:state_pressed="false" android:drawable="@color/tablight" />
<!-- Inactive tab -->
<item android:state_selected="false" android:state_focused="false"
android:state_pressed="false" android:drawable="@color/tabdark" />
<!-- Pressed tab -->
<item android:state_pressed="true" android:drawable="@color/tablight" />
<!-- Selected tab (using d-pad) -->
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@color/tablight" />
tabs_bg.xml
<TextView
android:id="@+id/tabsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textColor="@android:color/white"
android:textSize="15dip" />
button_tabs_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabsLayout" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/buttontab"
android:padding="10dip" android:gravity="center" android:orientation="vertical">
<Button
android:id="@+id/tabsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:textColor="@android:color/black"
android:textSize="15dip" />
</LinearLayout>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="tabdark">#333333</color>
<color name="tablight">#999999</color>
<color name="buttontab">#999966</color>
</resources>
这篇关于如何放置在android系统旁边的一个标签按钮? (相关UI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!