>如何在顶部设计定制的无线电组,
>这样点击那个按钮就像我们在标签主机中那样做….
显示获得的活动的功能
tabs.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="horizontal" > <RadioGroup androID:ID="@+ID/radioGroup1" androID:layout_wIDth="fill_parent" androID:layout_height="40dp" androID:orIEntation="horizontal" > <Radiobutton androID:ID="@+ID/rdb1" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_weight="0.33" androID:background="@androID:color/white" androID:button="@null" androID:gravity="center" androID:text="Tab1" androID:textcolor="@androID:color/black" androID:textSize="15sp" androID:textStyle="bold" /> <Radiobutton androID:ID="@+ID/rdb2" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_weight="0.33" androID:background="@androID:color/white" androID:button="@null" androID:gravity="center" androID:text="Tab2" androID:textcolor="@androID:color/black" androID:textSize="15sp" androID:textStyle="bold" /> </RadioGroup></linearLayout>
activity_main.xml中
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="horizontal" > <include layout="@layout/tabs"/></linearLayout>
MainActivity.java
public class MainActivity extends Activity { @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); }}
screen1.java& screen2.java r其他2项活动
解决方法 问题1如何创建自定义Radiobutton?答:您可以将自定义样式应用于Rediobutton.现在有一种非常简单的方法来为UI控件创建自定义样式.
在这里,我将向您展示如何为Rediobutton创建自定义样式:
<style name="MyRadiobuttonStyle" parent="@androID:style/Widget.Compoundbutton.Radiobutton"><item name="androID:button">@drawable/custom_btn_radio</item>
为按钮状态创建一个drawble选择器. RES /抽拉/ custom_btn_radio.xml
<selector xmlns:androID="http://schemas.androID.com/apk/res/androID"><item androID:state_checked="true" androID:state_window_focused="false" androID:drawable="@drawable/btn_radio_on" /><item androID:state_checked="false" androID:state_window_focused="false" androID:drawable="@drawable/btn_radio_off" /><item androID:state_checked="true" androID:state_pressed="true" androID:drawable="@drawable/btn_radio_on_pressed" /><item androID:state_checked="false" androID:state_pressed="true" androID:drawable="@drawable/btn_radio_off_pressed" /><item androID:state_checked="true" androID:state_focused="true" androID:drawable="@drawable/btn_radio_on_selected" /><item androID:state_checked="false" androID:state_focused="true" androID:drawable="@drawable/btn_radio_off_selected" /><item androID:state_checked="false" androID:drawable="@drawable/btn_radio_off" /><item androID:state_checked="true" androID:drawable="@drawable/btn_radio_on" />
问题2如何在单个Container中显示两个活动(也许它也是Activity的一部分)答:无法在单个Activity类中打开活动.您可以在一个Activity中打开多个Fragment.或其他方式在单选按钮选择时在运行时替换您的布局.据我所知,第一个是好方法.
总结以上是内存溢出为你收集整理的android – 自定义单选按钮,提供tabhost等功能全部内容,希望文章能够帮你解决android – 自定义单选按钮,提供tabhost等功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)