Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提供tabhost等功能的自定义单选按钮 如何在android中使用单选按钮实现tabHost的功能? 如何在顶部设计自定义radiobuton组 所以点击这个按钮就像我们在tab host中做的那样。。。。 在中显示活动的功能_Android - Fatal编程技术网

提供tabhost等功能的自定义单选按钮 如何在android中使用单选按钮实现tabHost的功能? 如何在顶部设计自定义radiobuton组 所以点击这个按钮就像我们在tab host中做的那样。。。。 在中显示活动的功能

提供tabhost等功能的自定义单选按钮 如何在android中使用单选按钮实现tabHost的功能? 如何在顶部设计自定义radiobuton组 所以点击这个按钮就像我们在tab host中做的那样。。。。 在中显示活动的功能,android,Android,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" &g

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>
<?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>
<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" />
screen1.java和screen2.java r其他2个活动

问题1如何创建自定义单选按钮

回答:您可以将自定义样式应用于重拨按钮。现在有非常简单的方法来为UI控件创建自定义样式。 在这里,我将向您展示如何包装用于重排按钮的自定义样式:

<style name="MyRadioButtonStyle" parent="@android:style/Widget.CompoundButton.RadioButton">
<item name="android:button">@drawable/custom_btn_radio</item>

@可牵引/定制无线

为按钮状态创建可绘制选择器res/drawable/custom_btn_radio.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>
<?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>
<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 如何在单个容器中显示两个活动(可能也是活动的一部分)
答案:无法在单个活动类中打开活动。您可以在单个活动中打开多个片段。或者以其他方式在运行时替换单选按钮上的布局。正如我所知,第一个问题是个好办法。

你可以从这个[问题][1]中了解你的问题。[1]: