gpt4 book ai didi

java - 为什么可以设置状态颜色?

转载 作者:太空宇宙 更新时间:2023-11-04 12:25:36 25 4
gpt4 key购买 nike

有一些我不知道为什么要设置的东西

android:theme="@style/AppTheme"

在AndroidManifest.xml中

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DetailActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".LineChartActivity1"></activity>
<activity android:name=".RealtimeLineChartActivity">
<!--android:theme="@style/AppTheme"-->

</activity>
<activity android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".Add_arg_activity"/>
</application>

RealtimeLineChartActivity 的 xml 是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme">

<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

但是!!!屏幕是这样的...我对这张图片感到非常抱歉,我在 stackoverflow 中没有足够的积分。

The main activity screen shot

The second activity screen shot(RealtimeLineChartActivity)

正如您在图片中看到的颜色,第二个是白色,第一个是我想要的,已应用于

@style/AppTheme

我不知道为什么。请给我一些有用的东西,我查了很多信息。

这是第二个的 Activity 代码:

public class RealtimeLineChartActivity extends DemoBase implements
OnChartValueSelectedListener {

private LineChart mChart;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_realtime_linechart);
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintResource(R.color.dark_grey);
tintManager.setStatusBarTintEnabled(true);

mChart = (LineChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);

// no description text
mChart.setDescription("");
mChart.setNoDataTextDescription("You need to provide data for the chart.");

// enable touch gestures
mChart.setTouchEnabled(true);

// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setDrawGridBackground(false);

// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(true);

// set an alternative background color
mChart.setBackgroundColor(Color.LTGRAY);

LineData data = new LineData();
data.setValueTextColor(Color.WHITE);

// add empty data
mChart.setData(data);

Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

// get the legend (only possible after setting data)
Legend l = mChart.getLegend();

// modify the legend ...
// l.setPosition(LegendPosition.LEFT_OF_CHART);
l.setForm(LegendForm.LINE);
l.setTypeface(tf);
l.setTextColor(Color.WHITE);

XAxis xl = mChart.getXAxis();
xl.setTypeface(tf);
xl.setTextColor(Color.WHITE);
xl.setDrawGridLines(false);
xl.setAvoidFirstLastClipping(true);
xl.setSpaceBetweenLabels(5);
xl.setEnabled(true);

YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(tf);
leftAxis.setTextColor(Color.WHITE);
leftAxis.setAxisMaxValue(100 f);
leftAxis.setAxisMinValue(0 f);
leftAxis.setDrawGridLines(true);

YAxis rightAxis = mChart.getAxisRight();
rightAxis.setEnabled(false);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.realtime, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.actionAdd:
{
addEntry();
break;
}
case R.id.actionClear:
{
mChart.clearValues();
Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show();
break;
}
case R.id.actionFeedMultiple:
{
feedMultiple();
break;
}
}
return true;
}

private int year = 2015;

private void addEntry() {

LineData data = mChart.getData();

if (data != null) {

ILineDataSet set = data.getDataSetByIndex(0);
// set.addEntry(...); // can be called as well

if (set == null) {
set = createSet();
data.addDataSet(set);
}

// add a new x-value first
data.addXValue(mMonths[data.getXValCount() % 12] + " " + (year + data.getXValCount() / 12));
data.addEntry(new Entry((float)(Math.random() * 40) + 30 f, set.getEntryCount()), 0);


// let the chart know it's data has changed
mChart.notifyDataSetChanged();

// limit the number of visible entries
mChart.setVisibleXRangeMaximum(120);
// mChart.setVisibleYRange(30, AxisDependency.LEFT);

// move to the latest entry
mChart.moveViewToX(data.getXValCount() - 121);

// this automatically refreshes the chart (calls invalidate())
// mChart.moveViewTo(data.getXValCount()-7, 55f,
// AxisDependency.LEFT);
}
}

private LineDataSet createSet() {

LineDataSet set = new LineDataSet(null, "Dynamic Data");
set.setAxisDependency(AxisDependency.LEFT);
set.setColor(ColorTemplate.getHoloBlue());
set.setCircleColor(Color.WHITE);
set.setLineWidth(2 f);
set.setCircleRadius(4 f);
set.setFillAlpha(65);
set.setFillColor(ColorTemplate.getHoloBlue());
set.setHighLightColor(Color.rgb(244, 117, 117));
set.setValueTextColor(Color.WHITE);
set.setValueTextSize(9 f);
set.setDrawValues(false);
return set;
}

private void feedMultiple() {

new Thread(new Runnable() {

@Override
public void run() {
for (int i = 0; i < 500; i++) {

runOnUiThread(new Runnable() {

@Override
public void run() {
addEntry();
}
});

try {
Thread.sleep(35);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
}

@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
Log.i("Entry selected", e.toString());
}

@Override
public void onNothingSelected() {
Log.i("Nothing selected", "Nothing selected.");
}
}

Here is my styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="colorPrimary">#3F51B5</item>
<!-- Light Indigo -->
<item name="colorPrimaryDark">#3949AB</item>
<!-- Dark Indigo -->
<item name="colorAccent">#00B0FF</item>
<!-- Blue -->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>

最佳答案

我的项目中有两个styles.xml。第一个是styles.xml,另一个是styles-v21.xml。我没有在styles-v21.xml中设置该项目。我使用的android版本是6.0 API-23,所以我复制了styles.xml中相同的项目。它就OK了。我的错!

The First

The Second

关于java - 为什么可以设置状态颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38429117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com