我的工具栏没有一直延伸到整个屏幕 (android)
My tool bar doesn't extend all the way across the screen (android)
我正在做一个非常简单的 activity,但是我无法让工具栏一直延伸到整个屏幕。这是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linearLayout"
android:background="@drawable/backgroundgradient"
tools:context="com.webnation.text2email.DisplayTextActivity">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/colorPrimary"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<ScrollView
android:id="@+id/widget54"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
>
<TextView
android:id="@+id/displayText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dip"
android:text="@string/eula"
tools:context=".DisplayText" />
</ScrollView>
</LinearLayout>
我的activity:
open class DisplayTextActivity : AppCompatActivity() {
private var nameOfFile = ""
lateinit var androidText: AndroidText
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.displaytext)
linearLayout.background = ContextCompat.getDrawable(this, Globals.getBackground(this))
val toolbar = findViewById(R.id.toolbar) as Toolbar
setSupportActionBar(toolbar)
val actionBar = supportActionBar
val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
val theme = preferences.getString(Globals.KEY_THEME, Globals.THEME_PRIMARY)
val iTheme = Globals.getTheme(theme)
val extras = intent.extras
if (extras != null) {
nameOfFile = extras.getString(Globals.keyFileName, Globals.FILE_EULA)
try {
androidText = AndroidText(nameOfFile, this@DisplayTextActivity) //Get the text of the eula from text file
displayText.text = Html.fromHtml(androidText.androidText)
} catch (e: Resources.NotFoundException) {
Timber.e(e, e.toString())
val dialog = WebNationAlertDialog(this@DisplayTextActivity)
dialog.setTitle("Error!")
dialog.setDialogText(resources.getString(R.string.resource_not_found))
dialog.setNeuText(resources.getString(R.string.ok)) {
dialog.dismiss()
setResult(Activity.RESULT_OK)
finish()
}
dialog.show()
}
Globals.setToolBarColor(iTheme, toolbar)
try {
assert(actionBar != null)
actionBar?.setDisplayHomeAsUpEnabled(true)
actionBar?.setHomeButtonEnabled(true)
actionBar?.setDisplayShowTitleEnabled(true)
var title = resources.getString(R.string.eulaTitle)
when (nameOfFile) {
Globals.FILE_EULA -> {
title = resources.getString(R.string.eulaTitle)
}
Globals.FILE_HELP -> {
title = resources.getString(R.string.fileHelpTitle)
}
}
actionBar?.setTitle(title)
} catch (ignored: Exception) {
Timber.e(ignored.toString())
}
} else {
setResult(Activity.RESULT_OK)
finish()
}
}
override fun onOptionsItemSelected(menuItem: MenuItem): Boolean {
if (menuItem.itemId == android.R.id.home) {
finish()
}
return super.onOptionsItemSelected(menuItem)
}
}
屏幕截图如下所示。我不确定哪里出了问题,因为我在其他几个活动中使用了这个布局的一个版本。
我怀疑您在父 LinearLayout 的 android:background="@drawable/backgroundgradient"
中有填充。要么从背景渐变中删除该填充,要么将填充应用于工具栏以外的其他视图。你有多种选择。祝你好运!
我正在做一个非常简单的 activity,但是我无法让工具栏一直延伸到整个屏幕。这是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linearLayout"
android:background="@drawable/backgroundgradient"
tools:context="com.webnation.text2email.DisplayTextActivity">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/colorPrimary"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<ScrollView
android:id="@+id/widget54"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
>
<TextView
android:id="@+id/displayText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dip"
android:text="@string/eula"
tools:context=".DisplayText" />
</ScrollView>
</LinearLayout>
我的activity:
open class DisplayTextActivity : AppCompatActivity() {
private var nameOfFile = ""
lateinit var androidText: AndroidText
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.displaytext)
linearLayout.background = ContextCompat.getDrawable(this, Globals.getBackground(this))
val toolbar = findViewById(R.id.toolbar) as Toolbar
setSupportActionBar(toolbar)
val actionBar = supportActionBar
val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
val theme = preferences.getString(Globals.KEY_THEME, Globals.THEME_PRIMARY)
val iTheme = Globals.getTheme(theme)
val extras = intent.extras
if (extras != null) {
nameOfFile = extras.getString(Globals.keyFileName, Globals.FILE_EULA)
try {
androidText = AndroidText(nameOfFile, this@DisplayTextActivity) //Get the text of the eula from text file
displayText.text = Html.fromHtml(androidText.androidText)
} catch (e: Resources.NotFoundException) {
Timber.e(e, e.toString())
val dialog = WebNationAlertDialog(this@DisplayTextActivity)
dialog.setTitle("Error!")
dialog.setDialogText(resources.getString(R.string.resource_not_found))
dialog.setNeuText(resources.getString(R.string.ok)) {
dialog.dismiss()
setResult(Activity.RESULT_OK)
finish()
}
dialog.show()
}
Globals.setToolBarColor(iTheme, toolbar)
try {
assert(actionBar != null)
actionBar?.setDisplayHomeAsUpEnabled(true)
actionBar?.setHomeButtonEnabled(true)
actionBar?.setDisplayShowTitleEnabled(true)
var title = resources.getString(R.string.eulaTitle)
when (nameOfFile) {
Globals.FILE_EULA -> {
title = resources.getString(R.string.eulaTitle)
}
Globals.FILE_HELP -> {
title = resources.getString(R.string.fileHelpTitle)
}
}
actionBar?.setTitle(title)
} catch (ignored: Exception) {
Timber.e(ignored.toString())
}
} else {
setResult(Activity.RESULT_OK)
finish()
}
}
override fun onOptionsItemSelected(menuItem: MenuItem): Boolean {
if (menuItem.itemId == android.R.id.home) {
finish()
}
return super.onOptionsItemSelected(menuItem)
}
}
屏幕截图如下所示。我不确定哪里出了问题,因为我在其他几个活动中使用了这个布局的一个版本。
我怀疑您在父 LinearLayout 的 android:background="@drawable/backgroundgradient"
中有填充。要么从背景渐变中删除该填充,要么将填充应用于工具栏以外的其他视图。你有多种选择。祝你好运!