【问题标题】:Adding a button to the android emulator skin将按钮添加到 android 模拟器皮肤
【发布时间】:2011-07-30 20:42:10
【问题描述】:

我正在尝试将按钮添加到默认模拟器外观之一。我使用布局文件来显示按钮,但我不确定如何映射它以便它实际执行某些操作。

【问题讨论】:

  • 你想为你的按钮分配一个点击处理程序吗?
  • 是的,但是要在皮肤上的一个按钮
  • 我想在源代码中更改实际的模拟器。

标签: android android-emulator android-layout


【解决方案1】:

您想在 onCreate 中使用类似这样的内容从布局 XML 中获取按钮:

Button xButton = (Button)findViewById(R.id.buttonX); //buttonX is the id you gave the button in the layout

然后您可以像这样在 onCreate 中为该按钮设置一个点击监听器:

xButton.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v) {
        // do stuff here    
}});

【讨论】:

  • 为什么这是公认的答案?问题是模拟器皮肤上的按钮而不是布局 xml。
  • 好问题,我想回想 9 年前,但我的答案并非针对模拟器,所以它似乎不完全适合这个问题。
【解决方案2】:

很晚了,但这是我发现的:

  1. 使用适当的按钮图像(渲染)创建您的皮肤
  2. 创建一个按钮覆盖图像,当您用鼠标将鼠标移到按钮上时,该图像将被绘制在按钮上(所有按钮都可以相同,因为它只是一个焦点指示器)
  3. 在您的皮肤中定义布局中的按钮(见下文)
  4. 对于每个按钮,您可以将其链接到特定的 qemu 代码(请参阅 https://android.googlesource.com/platform/external/qemu.git/+/8b9887163ce94928aec159956d1a61fc93bb949d/android/skin/file.c#122

布局:

parts {
  device {
     ...
  }
  portrait {
     ...
     buttons {
        search {                 // see qemu codes 
           image xxxx.png        // the overlay image to show on mouse move over
           x     00000           // the top-left coordinate to show the image
           y     00000           //
        }
     }
  }
}

PS:我很确定按钮大小取决于按钮图像尺寸。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-18
    • 2018-02-10
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    相关资源
    最近更新 更多