当我已经用完了样式和背景的选项时,如何在android xml中应用按钮的状态按下?
我有一个num键盘,我用按钮创建,并隐藏了我的android软键盘 这就是我的每个按钮对于不同数字的外观当我已经用完了样式和背景的选项时,如何在android xml中应用按钮的状态按下?,android,xml,Android,Xml,我有一个num键盘,我用按钮创建,并隐藏了我的android软键盘 这就是我的每个按钮对于不同数字的外观 <Button android:id="@+id/seven" android:text="7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"
<Button
android:id="@+id/seven"
android:text="7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/CustomStyle"
android:background="@drawable/gridlayout_border"
/>
请注意,我使用的是CustomStyle,其代码如下所示,文件名为button\u style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomStyle">
<item name="android:textSize">24dp </item>
<item name="android:textColor">#fdfdfd</item>
<item name="android:textStyle">bold </item>
<item name="android:padding">20dp</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="-10dp" android:right="0dp" android:top="-10dp"
>
<shape android:shape="rectangle">
<!--apply button background transparent, full opacity-->
<solid android:color="#00ffffff"/>
<stroke android:color="#ffffff" android:width="2dp"/>
</shape>
</item>
</layer-list>
24dp
#fdfdfd
大胆的
20dp
另外,我使用gridlayout_边框作为背景
gridlayout\u border.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomStyle">
<item name="android:textSize">24dp </item>
<item name="android:textColor">#fdfdfd</item>
<item name="android:textStyle">bold </item>
<item name="android:padding">20dp</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="-10dp" android:right="0dp" android:top="-10dp"
>
<shape android:shape="rectangle">
<!--apply button background transparent, full opacity-->
<solid android:color="#00ffffff"/>
<stroke android:color="#ffffff" android:width="2dp"/>
</shape>
</item>
</layer-list>
从那时起,我已经用完了按钮中的样式和背景标记。当按下num键盘上的按钮时,如何再应用一种样式/颜色
提前感谢您可以使用选择器确定视图的不同状态。大概是这样的:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
<!-- Write your focused state code-->
</item>
<item android:state_pressed="true">
<!-- Write your pressed state code-->
</item>
<item>
<layer-list>
<item android:left="-10dp" android:right="0dp" android:top="-10dp"
>
<shape android:shape="rectangle">
<!--apply button background transparent, full opacity-->
<solid android:color="#00ffffff"/>
<stroke android:width="2dp" android:color="#ffffff"/>
</shape>
</item>
</layer-list>
</item>
</selector>
您可以使用选择器确定视图的不同状态。大概是这样的:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
<!-- Write your focused state code-->
</item>
<item android:state_pressed="true">
<!-- Write your pressed state code-->
</item>
<item>
<layer-list>
<item android:left="-10dp" android:right="0dp" android:top="-10dp"
>
<shape android:shape="rectangle">
<!--apply button background transparent, full opacity-->
<solid android:color="#00ffffff"/>
<stroke android:width="2dp" android:color="#ffffff"/>
</shape>
</item>
</layer-list>
</item>
</selector>
check.check.我已经厌倦了上面的代码,得到了二进制xml错误,比如二进制xml文件行#202:错误膨胀类按钮和文件res/drawable/gridlayout_border.xml(来自drawable资源ID#0x7f020048i已经厌倦了上面的代码,获取二进制xml错误,如二进制xml文件行#202:从可绘图资源ID#0x7f020048膨胀类按钮和文件res/drawable/gridlayout_border.xml时出错