我的朋友为我制作了一个工具栏代码,它必须在操作栏下。如何将它添加到主ml布局以及主java活动?
public class Fencing {
public static void main(String[] args) {
double totalFencingUnits = 0;
double fencingUnitWeight = 2.5;
boolean b = true;
double corner = 0;
double core = 0;
double side = 0;
int i = 0;
int j = 0;
int[][] map = {
{ 0, 1, 1, 0 },
{ 1, 1, 1, 1 },
{ 1, 1, 1, 1 },
{ 1, 1, 0, 1 }
};
for (i = 0; i < map.length; i++) {
for (j = 0; j < map[0].length; j++) {
if (map[i][j] != 1 && map[i][j] != 0) {
b = false;
System.out.println("--> An invalid value of " + map[i][j] + " was found at " + i + "," + j);
}
if ( map[i][j] == 1){
//do the outer corners
if((i == 0 && (j == 0 || j == map.length - 1)) || (i == map.length - 1 && (j == 0 || j == map.length - 1))){
System.out.println("A corner " + map[i][j] + " was found at " + i + "," + j);
totalFencingUnits += 2;
switch (2*i - j ) {
case -3:
totalFencingUnits += map[i][j - 1] > 0?0:1;
totalFencingUnits += map[i + 1][j] > 0?0:1;
break;
case 6:
totalFencingUnits += map[i - 1][j] > 0?0:1;
totalFencingUnits += map[i ][j + 1] > 0?0:1;
break;
case 0:
totalFencingUnits += map[i][j + 1] > 0?0:1;
totalFencingUnits += map[i +1 ][j] > 0?0:1;
break;
case 3:
totalFencingUnits += map[i - 1][j] > 0?0:1;
totalFencingUnits += map[i ][j - 1] > 0?0:1;
break;
default:
break;
}
}
//do the outer sides
else if((i == 0 && (j != 0 && j != map.length - 1)) || (i == map.length - 1 && (j != 0 && j != map.length - 1))
|| (j == 0 && (i != 0 && i != map.length - 1)) || (j == map.length - 1 && (i != 0 && i != map.length - 1))){
System.out.println("A side " + map[i][j] + " was found at " + i + "," + j);
totalFencingUnits ++;
if ( i == 0){
totalFencingUnits += map[i][j - 1] > 0?0:1;
totalFencingUnits += map[i + 1][j] > 0?0:1;
totalFencingUnits += map[i][j + 1] > 0?0:1;
}
if (i == map.length - 1){
totalFencingUnits += map[i][j - 1] > 0?0:1;
totalFencingUnits += map[i -1 ][j] > 0?0:1;
totalFencingUnits += map[i][j + 1] > 0?0:1;
}
if ( j == 0){
totalFencingUnits += map[i - 1][j] > 0?0:1;
totalFencingUnits += map[i][j + 1] > 0?0:1;
totalFencingUnits += map[i + 1][j ] > 0?0:1;
}
if ( j == map.length - 1){
totalFencingUnits += map[i - 1][j] > 0?0:1;
totalFencingUnits += map[i][j - 1] > 0?0:1;
totalFencingUnits += map[i + 1][j ] > 0?0:1;
}
}
//now do the internals blocks
else {
System.out.println("An internal " + map[i][j] + " was found at " + i + "," + j);
totalFencingUnits += map[i - 1][j] > 0?0:1;
totalFencingUnits += map[i][j - 1] > 0?0:1;
totalFencingUnits += map[i ][j + 1] > 0?0:1;
totalFencingUnits += map[i + 1][j ] > 0?0:1;
}
}
}
}
if (b == false && i == 4) {
System.out.println("The map is invalid");
return;
} else {
System.out.println("Map is valid");
System.out.println("TOTAL FENCING UNITS: " + totalFencingUnits );
System.out.println("TOTAL FENCING WEIGHT: " + totalFencingUnits * fencingUnitWeight);
}
}
}
但现在我还没有和他联系。如何将它添加到主xml以及主java活动?
请帮帮我们!
答案 0 :(得分:0)
您需要创建一个自定义工具栏(最好是单独的xml文件,因为我们可以重复使用它)并使用include标记将其包含在您的xml文件中。
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
这里&#39;工具栏&#39;是布局文件夹中的xml文件(包含工具栏设计)。
如果您要删除操作栏,则可以设置“父母”&#39; style.xml的属性为&#39; Theme.AppCompat.Light.NoActionBar&#39;
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">