English 中文(简体)
如何建立无边界无 but州(如上述设计准则)?
原标题:How to create standard Borderless buttons (like in the design guideline mentioned)?

I was just checking the design guidelines and wondering about the borderless buttons. I goggled and tried to find in the source but can t bring it together by myself. Is this the normal Button widget but you add a custom (Android default) style? How to make these borderless buttons (of course you can set the background to empty, but then I don t have the divider)?

此处与设计准则链接:

enter image description here

最佳回答

消除一些混乱:

采取以下两个步骤: 规定纽伦堡背景归属为android:attr/selectableItemBackground,使你形成一个有反馈但没有背景的纽伦。

android:background="?android:attr/selectableItemBackground"

将无边界纽扣地与你的其他布局分开,其背景是android:attr/dividerVertical

android:background="?android:attr/dividerVertical"

要更好地了解这一点,就要安排在你的屏幕底部(如上正确图像)把科索沃/中西边界无).的纽芬兰组合起来。

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_alignParentBottom="true">
        <View
            android:layout_width="match_parent"
            android:layout_height="1dip"
            android:layout_marginLeft="4dip"
            android:layout_marginRight="4dip"
            android:background="?android:attr/dividerVertical"
            android:layout_alignParentTop="true"/>
        <View
            android:id="@+id/ViewColorPickerHelper"
            android:layout_width="1dip"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="4dip"
            android:layout_marginTop="4dip"
            android:background="?android:attr/dividerVertical" 
            android:layout_centerHorizontal="true"/>
        <Button
            android:id="@+id/BtnColorPickerCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@id/ViewColorPickerHelper"
            android:background="?android:attr/selectableItemBackground"
            android:text="@android:string/cancel" 
            android:layout_alignParentBottom="true"/>
        <Button
            android:id="@+id/BtnColorPickerOk"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="?android:attr/selectableItemBackground"
            android:text="@android:string/ok" 
            android:layout_alignParentBottom="true" 
            android:layout_toRightOf="@id/ViewColorPickerHelper"/>
    </RelativeLayout>
问题回答

简单地在<条码>Button上添加以下风格:

    style="?android:attr/borderlessButtonStyle"

source: http://developer.android.com/guide/topics/ui/controls/button.html#Borderless

然后,你可以在Karl swer上添加分裂器。

答复迟,但许多意见。 正如APICs < 11 ain t die,对这里感兴趣的人来说,这是一个骗局。

让我们的集装箱有希望的颜色(可能是透明的)。 之后,给你的子孙留下了一位有缺省透明度的彩色和一些有色的选子。 这样,你就有一个透明但又会变色(如 h)。 你们也可以增加某种估计(如 h)。 选择者应当如此:

res/drawable/selector_transparent_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" 
          android:exitFadeDuration="@android:integer/config_shortAnimTime">
     <item android:state_pressed="true"
         android:drawable="@color/blue" />

   <item android:drawable="@color/transparent" />
</selector>

纽伦堡应当有<代码>android:background=”@drawable/selector_transul_button。

PS:请您的集装箱有分机(android:divider=@android:drawable/... for AP < 11)

PS [Newbies]: you should define those colors in values/colors.xml

For the one who want borderless buttons but still animated when clicked. Add this in the button.

style="?android:attr/borderlessButtonStyle"

如果你们想要的是他们之间的鸿沟。 在线性布局中添加这一点。

style="?android:buttonBarStyle"

内 容 提 要

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal"
   style="?android:buttonBarStyle">

    <Button
        android:id="@+id/add"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/add_dialog" 
        style="?android:attr/borderlessButtonStyle"
        />

    <Button
        android:id="@+id/cancel"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/cancel_dialog" 
        style="?android:attr/borderlessButtonStyle"
        />

</LinearLayout>

For material style add style="@style/Widget.AppCompat.Button.Borderless" when using the AppCompat library.

http://code.google.com/p/iosdated/“rel=“noretinger”>。 我在座的有<条码>Button Bar:

/**
 * An extremely simple {@link LinearLayout} descendant that simply reverses the 
 * order of its child views on Android 4.0+. The reason for this is that on 
 * Android 4.0+, negative buttons should be shown to the left of positive buttons.
 */
public class ButtonBar extends LinearLayout {

    public ButtonBar(Context context) {
        super(context);
    }

    public ButtonBar(Context context, AttributeSet attributes) {
        super(context, attributes);
    }

    public ButtonBar(Context context, AttributeSet attributes, int def_style) {
        super(context, attributes, def_style);
    }

    @Override
    public View getChildAt(int index) {
        if (_has_ics)
            // Flip the buttons so that "OK | Cancel" becomes "Cancel | OK" on ICS
            return super.getChildAt(getChildCount() - 1 - index);

        return super.getChildAt(index);
    }

    private final static boolean _has_ics = Build.VERSION.SDK_INT >= 
                                        Build.VERSION_CODES.ICE_CREAM_SANDWICH;
}

这将是“K”和“Cancel”纽州加入的“LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:divider="?android:attr/dividerHorizontal"
          android:orientation="vertical"
          android:showDividers="middle">
    <!--- A view, this approach only works with a single view here -->
    <your.package.ButtonBar style="?android:attr/buttonBarStyle"
        android:id="@+id/buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1.0">
        <Button style="?android:attr/buttonBarButtonStyle"
            android:id="@+id/ok_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="@string/ok_button" />
        <Button style="?android:attr/buttonBarButtonStyle"
            android:id="@+id/cancel_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="@string/cancel_button" />
    </your.package.ButtonBar>
</LinearLayout>

这使你们看到了与无边界的纽州之间的方言。 你可以在框架中找到这些属性。 button BarStyle 是垂直分裂和dding。 button BarButtonStyle >为奥洛主题建立了<条码>无边界布特托克/代码>,但我认为,由于框架希望显示这一条,这应当是显示它的最有力方式。

查阅主题特性<条码>丁顿·巴斯特莱、<条码>、丁顿·巴特顿·斯特莱和<条码>无边界的ButtonStyle。

你们也可以通过法典使纽特人无边界:

TypedValue value= new TypedValue();
getApplicationContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, value, true);
 myButton.setBackgroundResource(value.resourceId);

For those who want to create borderless button programmatically for API s >= 8

ImageButton smsImgBtn = new ImageButton(this);
//Sets a drawable as the content of this button
smsImgBtn.setImageResource(R.drawable.message_icon);    
//Set to 0 to remove the background or for bordeless button
smsImgBtn.setBackgroundResource(0);

Another solution that should work on both older and newer android platform is to use

android:background="@android:color/transparent"

Button的观点。 但是,在增加上述线纽顿之后,不会提供触动反馈。

To provide touch feedback add the following code to Activity class

button.setOnTouchListener(new View.OnTouchListener() {          
    @Override
    public boolean onTouch(View view, MotionEvent event) {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:    
                ((Button)view).setBackgroundColor(Color.LTGRAY);
                break;
            case MotionEvent.ACTION_UP:
                ((Button)view).setBackgroundColor(Color.TRANSPARENT);
        }
        return false;
    }
});

它对我的工作罚款。

仍然搜查的人:

inherit your own style for Holo buttonbars:

<style name="yourStyle" parent="@android:style/Holo.ButtonBar">
  ...
</style>

或光线:

<style name="yourStyle" parent="@android:style/Holo.Light.ButtonBar">
  ...
</style>

and for borderless Holo buttons:

<style name="yourStyle" parent="@android:style/Widget.Holo.Button.Borderless.Small">
  ...
</style>

或光线:

<style name="yourStyle" parent="@android:style/Widget.Holo.Light.Button.Borderless.Small">
  ...
</style>

这就是你如何在不使用XML的情况下,在方案上建立一个无边界(flat)的纽州。

ContextThemeWrapper myContext = new ContextThemeWrapper(this.getActivity(), 
   R.style.Widget_AppCompat_Button_Borderless_Colored);

Button myButton = new Button(myContext, null, 
   R.style.Widget_AppCompat_Button_Borderless_Colored);

Use the below code in your xml file. Use android:background="#00000000" to have the transparent color.

<Button
   android:id="@+id/btnLocation"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="#00000000"
   android:text="@string/menu_location"
   android:paddingRight="7dp"
/>

如果你想在方案上做到同样:

(这是C#,但很容易移植到 Java)

Button button = new Button(new ContextThemeWrapper(Context, Resource.Style.Widget_AppCompat_Button_Borderless_Colored), null, Resource.Style.Widget_AppCompat_Button_Borderless_Colored);

计算机

    <Button
       style="@style/Widget.AppCompat.Button.Borderless.Colored"
    .../>

遵照这一守则,为了从方案上消除背景可借鉴(@drawable/bg),我们必须规定一个参数无效。

Button btn= new Button(this);
btn.setText("HI");
btn.setBackground(null);

出于某种原因,没有<代码> 字面=”植被。 Holo.Button.Borderless" nor android:background=”?android:attr/selectableItemBackground”在我工作。 更精确的<代码> Widget.Holo.Button.Borderless do the work on Anders 4.0, but don t work on 2.3.3. 我在这两种版本上的骗子是:android:background="@drawable/transul”和本XML转/drawable/transul.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" >
</shape>

Plain head through the wall approach.

A great slide show on how to achieve the desired effect from Googles Nick Butcher (start at slide 20). He uses the standard android @attr to style the button and divider.

在顶端的回答中,你也可以使用暗色背景的见解,如线拉伊特。

<View
    android:layout_width="match_parent"
    android:layout_height="1dip"
    android:layout_marginBottom="4dip"
    android:layout_marginLeft="4dip"
    android:layout_marginRight="4dip"
    android:layout_marginTop="4dip"
    android:background="@android:color/darker_gray"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="4dip"
    android:orientation="horizontal"
    android:weightSum="1">

    <Button
        android:id="@+id/button_decline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight="0.50"
        android:background="?android:attr/selectableItemBackground"
        android:padding="10dip"
        android:text="@string/decline"/>

    <View
        android:layout_width="1dip"
        android:layout_height="match_parent"
        android:layout_marginLeft="4dip"
        android:layout_marginRight="4dip"
        android:background="@android:color/darker_gray"/>

    <Button
        android:id="@+id/button_accept"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_weight="0.50"
        android:background="?android:attr/selectableItemBackground"
        android:padding="10dip"
        android:text="@string/accept"/>
</LinearLayout>

如果你是横向的,如果你是垂直的,那么你就希望把高压定在1dip和宽度上。





相关问题
Very basic WPF layout question

How do I get this listbox to be maxiumum size, i.e. fill the group box its in. I ve tried width="auto" Height="auto", width="stretch" Height="stretch" annoyingly at the moment, it dynamicly sizes to ...

How to align the text to top of TextView?

How to align the text to top of a TextView? Equivalent Android API for Swings setInsets()? that is top of text should start be in (0,0) of TextView <?xml version="1.0" encoding="utf-8"?> <...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para Centred paragrpah , :align=> center However, this does not work with flows: flow(:align=> ...

Overlaying with CSS

I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...

How do you normally make a program look beautiful? [closed]

How can I make an Application look nice and not like an amateur pulled it together? I mean graphic-wise. Is there some sort of book you can read regarding beautiful program layouts, etc? I put this ...

热门标签