定义默认Button

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;

public class Snippet164 {

public static void main (String [] args) {
 Display display = new Display ();
 Shell shell = new Shell (display);
 
 Label label = new Label (shell, SWT.NONE);
 label.setText ("Enter your name:");
 Text text = new Text (shell, SWT.BORDER);
 text.setLayoutData (new RowData (100, SWT.DEFAULT));
 Button ok = new Button (shell, SWT.PUSH);
 ok.setText ("OK");
 ok.addSelectionListener(new SelectionAdapter() {
  public void widgetSelected(SelectionEvent e) {
   System.out.println("OK");
  }
 });
 Button cancel = new Button (shell, SWT.PUSH);
 cancel.setText ("Cancel");
 cancel.addSelectionListener(new SelectionAdapter() {
  public void widgetSelected(SelectionEvent e) {
   System.out.println("Cancel");
  }
 });
 //定义默认Button
 shell.setDefaultButton (cancel);
 
 shell.setLayout (new RowLayout ());
 shell.pack ();
 shell.open ();
 while (!shell.isDisposed ()) {
  if (!display.readAndDispatch ()) display.sleep ();
 }
 display.dispose ();
}

### Android Button 默认样式 在 Android 中,默认情况下 `Button` 控件会应用系统的默认主题样式。对于不同版本的 Android 和不同的设备制造商,这些默认样式可能会有所不同。 当创建一个标准的 `Button` 而不指定任何额外属性时,该按钮将继承当前应用程序的主题设置中的默认外观[^1]。具体来说: - **背景颜色**:通常采用的是基于所选主题的颜色方案的一部分。例如,在 Material Design 主题下,默认背景颜色通常是通过 `?attr/colorPrimary` 属性来决定的。 - **文字颜色**:同样依赖于主题配置文件中定义的文字颜色属性,比如 `?attr/colorOnSurface` 可能用于表示正常状态下的文本颜色[^3]。 为了查看确切的默认样式细节,可以查阅特定 API 级别的官方文档或源码资源。此外,如果想要自定义按钮样式,则可以通过 XML 文件定义新的风格并将其应用于目标组件上,如下所示: ```xml <!-- 定义一个新的样式 --> <style name="AppTheme.Button" parent="Widget.MaterialComponents.Button"> <!-- 设置一些属性 --> </style> ``` 之后可以在布局文件里这样使用这个新样式的按钮: ```xml <Button android:id="@+id/my_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click Me!" android:theme="@style/AppTheme.Button"/> ``` 上述代码片段展示了如何为按钮设定一种名为 `AppTheme.Button` 的主题,这允许开发者覆盖默认的行为和视觉特性。 #### 关于 Hotseat 功能中的 All App 按钮 值得注意的是,在某些项目如 Launcher 应用程序中,可能涉及到更复杂的 UI 组件设计,像 hotseat 上添加 all app 按钮这样的操作涉及到了多个类之间的交互以及 XML 布局文件的修改[^4]。不过这部分内容主要针对特定应用场景,并不是一般意义上的按钮默认样式讨论范围之内。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值