【问题标题】:Button not showing the pressed state?按钮不显示按下状态?
【发布时间】:2013-01-16 18:33:40
【问题描述】:

当我点击按钮时,它没有显示按下状态。请帮忙。谢谢

我的代码:

    <item name="android:textColor" >#000</item>
    <item name="android:textSize" >20dp</item>
    <item name="android:background">@drawable/note_icon</item>

</style>

按钮

    android:id="@+id/createnote"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/Createnote"
    style="@style/Create_text" />

这是我的布局和代码:

createnote.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {
    // TODO Auto-generated method stub

        //  v.setPressed(true);

    Intent intent = new Intent(getApplicationContext(), Add_Task.class);
    startActivity(intent);
        }
    });

【问题讨论】:

    标签: android android-button android-styles


    【解决方案1】:

    您是否创建了一个选择器来定义按下按钮时的行为?

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item 
            android:state_enabled="false"
            android:drawable="@drawable/btn_XXXX" />
       <item 
            android:state_pressed="true" 
            android:state_enabled="true"
            android:drawable="@drawable/btn_YYYY" />
       <item 
            android:state_focused="true" 
            android:state_enabled="true"
            android:drawable="@drawable/btn_ZZZZ" />
        <item 
            android:state_enabled="true"
            android:drawable="@drawable/btn_WWWWW" />
    </selector>
    

    【讨论】:

    • 您好,感谢您的回答。我需要将此选择器放在“菜单”或“样式”中。
    • 这是一个新文件 res/drawable/new_button.xml,您可以在按钮 xml 中将其与 android:background="@drawable/new_button" 一起使用
    • 这种利用不限于背景,您可以使用选择器来改变文字颜色(链接1)或形状(链接2)。链接 1:stackoverflow.com/a/4692899/1720391 - 链接 2:samir-mangroliya.blogspot.fr/2012/11/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2022-12-07
    相关资源
    最近更新 更多