如何在我的应用程序上添加材料设计



我有一个大问题。使用Eclipse(我有最新的Android 5.0的API和SDK),我试图用材料设计来改造我的应用程序。问题是Eclipse似乎无法识别代码。我会尽量详细说明:这是我的主要代码:

主要活动.java

public class MainActivity extends Activity implements OnClickListener {
private final static String RADIO_STATION_URL = "http://178.32.137.180:8665/stream";
private ProgressBar playSeekBar;
private Button buttonPlay;
private Button buttonStopPlay;
private MediaPlayer player;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initializeUIElements();
    initializeMediaPlayer();
}
private void initializeUIElements() {
    playSeekBar = (ProgressBar) findViewById(R.id.progressBar1);
    playSeekBar.setMax(100);
    playSeekBar.setVisibility(View.INVISIBLE);
    buttonPlay = (Button) findViewById(R.id.buttonPlay);
    buttonPlay.setOnClickListener(this);
    buttonStopPlay = (Button) findViewById(R.id.buttonStopPlay);
    buttonStopPlay.setEnabled(false);
    buttonStopPlay.setOnClickListener(this);
}
public void onClick(View v) {
    if (v == buttonPlay) {
        startPlaying();
    } else if (v == buttonStopPlay) {
        stopPlaying();
    }
}
private void startPlaying() {
    buttonStopPlay.setEnabled(true);
    buttonPlay.setEnabled(false);
    playSeekBar.setVisibility(View.VISIBLE);
    player.prepareAsync();
    player.setOnPreparedListener(new OnPreparedListener() {
        public void onPrepared(MediaPlayer mp) {
            player.start();
        }
    });
}
private void stopPlaying() {
    if (player.isPlaying()) {
        player.stop();
        player.release();
        initializeMediaPlayer();
    }
    buttonPlay.setEnabled(true);
    buttonStopPlay.setEnabled(false);
    playSeekBar.setVisibility(View.INVISIBLE);
}
private void initializeMediaPlayer() {
    player = new MediaPlayer();
    try {
        player.setDataSource(RADIO_STATION_URL);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
        public void onBufferingUpdate(MediaPlayer mp, int percent) {
            playSeekBar.setSecondaryProgress(percent);
            Log.i("Buffering", "" + percent);
        }
    });
}
@Override
protected void onPause() {
    super.onPause();

}

};

关于res/values的Styles.xml

<resources>
<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@android:style/Theme.Black">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular 
         API-level can go here. -->
</style>
</resources>

我正试图遵循此指南->http://android-developers.blogspot.gr/2014/10/appcompat-v21-material-design-for-pre.html但我在第一点之后被阻止了,活动扩展到ActionBarActivity(完成)。。。我能帮忙吗?我只想将材料设计(黑色)应用于我的应用程序。。有人能帮我吗?我对安卓的这一部分有点陌生,所以,要非常详细。

您需要将项目中的依赖项添加到appcompatv7库,以支持除SDK 5.0 之外的设备上的材料设计

以下是如何在eclipse中设置appcompat库的说明:https://developer.android.com/tools/support-library/setup.html

之后,你需要定义你的主题如下:

<style name="AppBaseTheme" parent="Theme.AppCompat">
</style>

以及您扩展ActionBarActivity:的所有活动

public class MainActivity extends ActionBarActivity {
}

相关内容

  • 没有找到相关文章

最新更新