我创建了一个带有不同文本的切换按钮,用于关闭/打开:
<ToggleButton
android:id="@+id/PTT_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="pushtotalk"
android:text="@string/ptt"
android:textOn="Push To Talk On"
android:textOff="Push To Talk Off"/>
...
public void pushtotalk(View view) {
boolean on = ((ToggleButton) view).isChecked();
if (on) {
Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)",
Toast.LENGTH_LONG).show();
} else {
// etc
}
当开关关闭时,按钮看起来不错,但是当我打开时,框外出现浅蓝色,这里发生了什么?
编辑:默认切换按钮,没有自定义图像。
编辑也许与按钮约束它的布局有关?
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/top_lvl_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<FrameLayout android:id="@+id/mainFrame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:paddingTop="10dip"
android:paddingLeft="6dip"
android:paddingRight="6dip"
>
<!-- (1) inCallPanel: the main set of in-call UI elements -->
<RelativeLayout android:id="@+id/inCallPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- Slide hints: if the "sliding card" feature is enabled,
one or the other of these is visible at any given moment
(see updateCardSlideHints()). -->
<!-- Slide hint and arrow *above* the main body of the card,
shown when the card is in the *bottom* position. -->
<!-- This hint's position onscreen is static: the Y value is set
so that the hint will be visible just above the top edge of
the CallCard when the CallCard is in the "bottom" position.
The resources here describe the portrait mode layout; see
InCallScreen.ConfigurationHelper.applyConfigurationToLayout()
for the differences in landscape mode. -->
<LinearLayout android:id="@+id/slideUp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@null"
android:visibility="gone"
>
<TextView android:id="@+id/slideUpHint"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@android:drawable/arrow_up_float"
/>
</LinearLayout>
<!-- Slide hint and arrow *below* the main body of the card,
shown when the card is in the *top* position. -->
<!-- This hint's position onscreen is static: the Y value is set
so that the hint will be visible just below the bottom edge of
the CallCard when the CallCard is in the "top" position.
The resources here describe the portrait mode layout; see
InCallScreen.ConfigurationHelper.applyConfigurationToLayout()
for the differences in landscape mode. -->
<LinearLayout android:id="@+id/slideDown"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@null"
android:visibility="gone"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@android:drawable/arrow_down_float"
/>
<TextView
android:id="@+id/slideDownHint"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/stats"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/codec"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</RelativeLayout> <!-- End of inCallPanel -->
</FrameLayout> <!-- End of mainFrame -->
<!-- The sliding drawer control containing the DTMF dialer. This has been
moved so that it is a sibling of mainFrame, instead of being a child.
Doing so allows us to expand to the full width of the screen, instead
of being confined to the mainFrame's layout -->
<SlidingDrawer
android:id="@+id/dialer_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:topOffset="5px"
android:bottomOffset="7px"
android:handle="@+id/dialer_tab"
android:content="@+id/dtmf_dialer"
android:allowSingleTap="false">
<ImageButton
android:id="@id/dialer_tab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_dialpad_tray"
android:background="@drawable/tray_handle_normal"/>
<include
layout="@layout/dtmf_twelve_key_dialer"
android:id="@id/dtmf_dialer"/>
</SlidingDrawer>
<ToggleButton
android:id="@+id/PTT_button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="pushtotalk2"
android:text="@string/ptt2"
android:layout_x="20dp"
android:layout_y="400dp"
android:textOn="Push To Talk On"
android:textOff="Push To Talk Off"/>
<EditText
android:id="@+id/editText1"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="150dp"
android:layout_y="400dp"
android:ems="10" >
<requestFocus />
</EditText>
</AbsoluteLayout>