Answer the question
In order to leave comments, you need to log in
How to get the SeekBar to display properly?
I am writing a simple application for smoothly changing the backlight level of the screen (actually analogous to what is in the settings). SeekBar on the Api 22 screen is displayed strangely: the slider is located separately,
.
And when you start on a real device, the message "App is abnormal abou to quit" appears, but the program works stably, and on Genymotion it crashes when you try to change the brightness.
Here are the sources:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_weight="5"
android:textSize="40sp"
android:text="Яркость:" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="5"
android:min="15"
android:max="200"
android:progress="3"
/>
</LinearLayout>
package com.example.backlight;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import java.lang.String;
import java.text.BreakIterator;
public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener{
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SeekBar seekBar = (SeekBar)findViewById(R.id.seekBar);
seekBar.setOnSeekBarChangeListener(this);
textView = (TextView)findViewById(R.id.textView);
textView.setText("Яркость: " + Settings.System.getString(this.getContentResolver(),"screen_brightness"));
seekBar.setProgress(Integer.parseInt(Settings.System.getString(this.getContentResolver(),"screen_brightness")));
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS, seekBar.getProgress());
textView.setText(String.valueOf(seekBar.getProgress()));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question