Я создал пост в блоге о том, как это сделать в Swift 3, и чтобы код был простым и читабельным.
Вы можете найти его здесь:
http://master-method.com/index.php/2016/11/23/sort-a-sequence-ie-arrays-of- objects-multi-properties-in-swift-3 /Вы также можете найти репозиторий GitHub с кодом здесь:
https://github.com/jallauca /SortByMultipleFieldsSwift.playground
Суть всего этого, скажем, если у вас есть список местоположений, вы сможете сделать это:
struct Location {
var city: String
var county: String
var state: String
}
var locations: [Location] {
return [
Location(city: "Dania Beach", county: "Broward", state: "Florida"),
Location(city: "Fort Lauderdale", county: "Broward", state: "Florida"),
Location(city: "Hallandale Beach", county: "Broward", state: "Florida"),
Location(city: "Delray Beach", county: "Palm Beach", state: "Florida"),
Location(city: "West Palm Beach", county: "Palm Beach", state: "Florida"),
Location(city: "Savannah", county: "Chatham", state: "Georgia"),
Location(city: "Richmond Hill", county: "Bryan", state: "Georgia"),
Location(city: "St. Marys", county: "Camden", state: "Georgia"),
Location(city: "Kingsland", county: "Camden", state: "Georgia"),
]
}
let sortedLocations =
locations
.sorted(by:
ComparisonResult.flip <<< Location.stateCompare,
Location.countyCompare,
Location.cityCompare
)
Я справляюсь с этим в своих играх для Android, вызывая следующую строку в onCreate () моего Activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
. Затем я могу выключить и включить полноэкранный режим, используя следующие код в моем классе активности (обычно вызывается из параметра меню) (переменная m_contentView - это представление из findViewById () с использованием идентификатора, который вы использовали при вызове setContentView () в вашем on create)
private void updateFullscreenStatus(boolean bUseFullscreen)
{
if(bUseFullscreen)
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
else
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
m_contentView.requestLayout();
}
Я использую этот метод во всех мои игры без проблем.
Почему вы говорите
requestWindowFeature (Window.FEATURE_NO_TITLE); is not an option of course
?
::EDIT::
Well if you are trying to dynamically show and hide it during the lifetime of the activity I am not sure if you can do that with the official Window Title due to the note that has been mentioned about window features needing to be set before setContentView() is called (link)
One thing that you could do is implement your own title bar and dynamically show and hide that... I put together this example that should set you o nthe right track
Here is the layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:fadingEdgeLength="0sp"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myTitleBarLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/myTitleBarTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:paddingTop="4dip"
android:paddingBottom="4dip"
android:paddingLeft="6dip"
android:textStyle="bold"
android:shadowColor="#BB000000"
android:shadowRadius="3.0"
android:shadowDy=".25"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#CCEEEEEE"
android:padding="10dip"
/>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<!-- Insert your regular layout stuff here -->
<Button android:id="@+id/toggle_title_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle Title"
/>
</ScrollView>
</LinearLayout>
And here is the code for the main activity that will allow you to toggle our custom title bar on and off
package com.snctln.test.HelloGridView;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class HelloGridView extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView)this.findViewById(R.id.myTitleBarTextView);
tv.setBackgroundColor(0xFF848284);
tv.setTextColor(0xFFFFFFFF);
Button toggleTitleButton = (Button)this.findViewById(R.id.toggle_title_button);
toggleTitleButton.setOnClickListener( new OnClickListener()
{
@Override
public void onClick(View v)
{
LinearLayout ll = (LinearLayout)findViewById(R.id.myTitleBarLayout);
if(ll.getVisibility() == View.GONE)
{
ll.setVisibility(View.VISIBLE);
}
else
{
ll.setVisibility(View.GONE);
}
}
});
}
}
It doesn't look perfect, but you can always play with the layout some more to do that.
My other thought is if you just want to hide everything to show a progress bar why not use the ProgressDialog?
This class is pretty easy to use...
progressDlg = ProgressDialog.show(context, getString(R.string.progress_dialog_title_prepare), getString(R.string.progress_dialog_body_prepare));
// do long running operation
if(operationFailed)
{
progressDlg.cancel();
}
else
{
progressDlg.dismiss();
}
, что невозможно в соответствии с документами и группой разработчиков Android. чтобы реализовать это, вам нужно добавить элемент макета, похожий на строку заголовка, с вашим текстом и полосой выполнения и скрыть / показать, когда вам это нужно. прямо сейчас - другого пути нет, так как управление строкой заголовка может быть выполнено только до вызова setContentView и не может быть изменено после.