wangy 发表于 2021-7-1 08:27:55

【lua教程】拖动条音量调节

require "import"
import "android.app.*"
import "android.os.*"
import "android.widget.*"
import "android.view.*"
import "android.content.*"
import "android.media.AudioManager"
layout={
LinearLayout;
orientation="vertical";
layout_width="match_parent";
layout_height="fill";
{
    SeekBar;
    id="seekber";
    layout_width="match_parent";
};
{
    TextView;
    textSize="40sp";
    layout_width="match_parent";
    layout_height="60dp";
    textColor="0xD14335C7";
    text="当前音量:(自动取整)";
};
{
    TextView;
    textSize="60sp";
    id="edit";
};
};

activity.setTheme(android.R.style.Theme_DeviceDefault_Light)--设置md主题
activity.setTitle("拖动条音量调节")
activity.setContentView(loadlayout(layout))
a="请调整上方拖动条"
istrue=false
function bbc()
edit.text=""..a..""
if istrue == true then
    if a>20 then
      edit.text="音量最大"
    end
end
end
seekber.Progress=15
seekber.setOnSeekBarChangeListener{
onStartTrackingTouch=function()
    activity.getSystemService(Context.AUDIO_SERVICE).setStreamVolume(AudioManager.STREAM_MUSIC, seekber.Progress/4.5, 0)
    activity.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE)
    if istrue==true then
      a=seekber.Progress/4.5
      bbc(a)
    end
end,
onStopTrackingTouch=function()
    activity.getSystemService(Context.AUDIO_SERVICE).setStreamVolume(AudioManager.STREAM_MUSIC, seekber.Progress/4.5, 0)
    activity.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE)
    if istrue==true then
      a=seekber.Progress/4.5
      bbc(a)
    end
end,
onProgressChanged=function()
    activity.getSystemService(Context.AUDIO_SERVICE).setStreamVolume(AudioManager.STREAM_MUSIC, seekber.Progress/4.5, 0)
    activity.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE)
    if istrue==true then
      a=seekber.Progress/4.5
      bbc(a)
    end
    istrue=true
end}
页: [1]
查看完整版本: 【lua教程】拖动条音量调节