我正在尝试像这样自定义我的搜索栏:
在API级别<23时,即使seekbar的进度等于0,也可以看到进度线.但是在API级别= 23时,我有一个奇怪的问题:进度线在相同的条件下没有显示= /我想看到这一行,因为它澄清使用我的搜索栏的边界.
我的seek_bar_progress_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/seek_bar_track" />
<item android:id="@android:id/secondaryProgress">
<scale
android:drawable="@drawable/seek_bar_track"
android:scaleWidth="100%" />
</item>
<item android:id="@android:id/progress">
<scale
android:drawable="@drawable/seek_bar_track"
android:scaleWidth="100%" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我的style.xml:
<style name="seek_bar_style" parent="android:Widget.Holo.Light.SeekBar">
<item name="android:progressDrawable">@drawable/seek_bar_progress_bar</item>
<item name="android:indeterminateDrawable">@drawable/seek_bar_progress_bar</item>
<item name="android:thumb">@drawable/seek_bar_thumb_selector</item>
</style>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
为此我做了下面的代码
我已经为seekbar progressDrawable创建了drawable让我知道如果需要代码,我会在这里发布.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/llScale"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingBottom="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/sliderText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Bernard"
android:textColor="@color/blue"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/slider_background"
android:padding="3dp">
<SeekBar
android:id="@+id/ratingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:max="10"
android:maxHeight="100dp"
android:thumbTintMode="multiply"
android:progressDrawable="@drawable/progressbar"
android:thumb="@drawable/ic_slider_secondary"/>
<TextView
android:id="@+id/seekBarHint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Drag slider across"
android:textColor="@color/dark_gray"/>
</FrameLayout>
<TextView
android:id="@+id/progressText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_slider_progress"
android:gravity="center"
android:textColor="@color/white"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但是上面的代码我得到的是如下图像
浅红色没有被完全填充,它留下一些空间,并在最后的圆圈走出边界.
摇篮
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId …Run Code Online (Sandbox Code Playgroud) 我已经设定:
mSeekBar.setMax(mp.getDuration()); // 8480
Run Code Online (Sandbox Code Playgroud)
完成Audiofile后,我得到的是:
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mediaPlayer)
{
Log.e("onComplete>>", ""+mediaPlayer.getCurrentPosition());
// mediaPlayer.getCurrentPosition() = 8192
Log.e("getDuration", ""+mediaPlayer.getDuration());
// mediaPlayer.getDuration() = 8480
if(mediaPlayer.getCurrentPosition()>=mediaPlayer.getDuration())
{
// Why never get called???
}
}
});
Run Code Online (Sandbox Code Playgroud)
那么,为什么MediaPlayer的当前位置永远不会达到音频文件的总持续时间?
或者在技术上我们可以说:
为什么不?
mediaPlayer.getCurrentPosition()==mediaPlayer.getDuration()
Run Code Online (Sandbox Code Playgroud)
为什么总是
OnCompletion侦听器中的mediaPlayer.getCurrentPosition()<mediaPlayer.getDuration()?
例如:
我有一个播放符号来启动播放器.现在,当我按下播放符号时,它将转换为暂停符号.
我有一个audiodfile的Maxduration.
现在我想在完全播放音频文件时将暂停符号转换为播放符号.所以我正在做的是检查:
if(mediaPlayer.getCurrentPosition()>=mediaPlayer.getDuration())
{
// Convert Imagview from Pause to Play
// But never get called
}
Run Code Online (Sandbox Code Playgroud) 我有一个这样的自定义Android搜索栏,以及它可以移动到的位置.它从中间开始:
我想首先移动滑块,然后检查它是否已保存.我有一个使用TouchAction的方法:
public void moveSeekBar(){
WebElement seekBar = appiumDriver.findElementById("com.feverapp:id/SymptomTrackingActivity_var");
//Get start point of seekbar.
int startX = seekBar.getLocation().getX();
System.out.println(startX);
//Get end point of seekbar.
int endX = seekBar.getSize().getWidth();
System.out.println(endX);
//Get vertical location of seekbar.
int yAxis = seekBar.getLocation().getY();
//Set slidebar move to position.
// this number is calculated based on (offset + 3/4width)
int moveToXDirectionAt = 786;
System.out.println("Moving seek bar at " + moveToXDirectionAt+" In X direction.");
//Moving seekbar using TouchAction class.
TouchAction act=new TouchAction(appiumDriver);
act.press(startX,yAxis).moveTo(moveToXDirectionAt,yAxis).release().perform();
}
Run Code Online (Sandbox Code Playgroud)
我注意到的一点:
我使用自定义搜索栏drawable并在我的xml中将其进度设置为50.它在Android Studio Preview中显示完美,但在设备中,背景颜色与进度颜色相同.我正在使用Android版本的Nexus 5:6.0.1.以下是代码和屏幕截图:
搜索栏:
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ivRepeat"
android:indeterminate="false"
android:maxHeight="2dp"
android:minHeight="2dp"
android:progress="50"
android:progressDrawable="@drawable/progress_drawable"
android:thumbTint="@color/seekColor" />
Run Code Online (Sandbox Code Playgroud)
progress_drawable.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<solid android:color="#F7CCBD" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="@color/seekColor" />
</shape>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
seekColor值:#87DED5
任何想法为什么会发生这种情况以及如何解决它?
我想做的是如下图所示。recyclerView使用中的语音注释MediaPlayer。
当按下播放按钮时,音频应该播放,当音频结束时,将搜索栏设置为 0 并停止播放器。
如果正在播放音频音符并且用户尝试播放新的音符,应用程序还应该避免同时播放音频。我该如何做类似的事情?我应该在MediaPlayer用户每次单击播放按钮时创建一个播放器还是始终使用同一播放器?
java android android-mediaplayer android-seekbar android-recyclerview
我需要像我在下面的图片中提到的价格范围搜索栏或滑块.任何帮助或示例代码将不胜感激.
提前致谢.
试图制作一个自定义SeekBar.我想实现这一目标.
到目前为止我所做的就是这个.我无法找到进度条上圆角的方法.
有人可以帮忙吗?这是我的代码
main_activity.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="30dp"
android:progressDrawable="@drawable/styled_progress"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:progress="90"
android:thumb="@drawable/thumbler_small"
android:maxHeight="30dp"
android:layout_marginTop="125dp"
android:layout_marginBottom="15dp"
android:indeterminate="false" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
styled_progress.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<gradient
android:startColor="#d2e5ff"
android:endColor="#d2e5ff"
android:angle="45"
/>
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<gradient
android:startColor="#808080"
android:endColor="#808080"
android:angle="270"
/>
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#c5e6eb"
android:endColor="#61cabb"
android:angle="45" />
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud) 我想在设置中使用Seekbar选择数字1到10.有没有办法做到这一点?我延长PreferenceActivity了我的设置活动.
正如我从这里发现的那样,但我不知道如何在里面创建Seekbar PreferenceScreen.预先感谢.这是活动
public class UserSettingActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings); }
}
Run Code Online (Sandbox Code Playgroud)
和setting.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/pref_user_profile" >
<EditTextPreference
android:title="@string/pref_user_name"
android:summary="@string/pref_user_name_summary"
android:key="prefUsername"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_update_setting" >
<CheckBoxPreference
android:defaultValue="false"
android:key="prefSendReport"
android:summary="@string/pref_send_report_summary"
android:title="@string/pref_send_report" >
</CheckBoxPreference>
<ListPreference
android:key="prefSyncFrequency"
android:entries="@array/syncFrequency"
android:summary="@string/pref_sync_frequency_summary"
android:entryValues="@array/syncFrequencyValues"
android:title="@string/pref_sync_frequency" />
</PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud) 我有一些离散seekbar的,我想在进度上更改自定义刻度线的颜色,但我无法找到解决方案。我已经读到有一个错误,AppCompatSeekbar它在前面制作刻度标记,thumb但这里的想法是在进度颜色更改时更改刻度标记的颜色。
现在进度是绿色的,但是当它到达刻度线时,刻度线保持灰色,它不会将其颜色更改为绿色。
是否可以在进度上更改刻度线颜色,如果可以,我该如何实现?提前致谢。
在这里你可以看到附加的图像,我相信这会让事情更清楚: